Hi,
I am curious how to use If - else logic and error trapping with keyboard maestro macros?
Like this simplistic example...
If (
Safari app is active
){
Speak text "Safari is active"
}else{
Speak text "Safari is not active"
}
Is there some way to do this with KM
Like this?
There are other options in the dropdown under the application condition, like: is/is not running, is/not hidden.
You might also want to look at Switch/Case action
5 Likes
Nige_S
July 31, 2022, 8:25am
3
@evanfuchs has nicely covered conditional branching via If/Else and others, but if you do also want actual error trapping you should look at the Try/Catch action.
3 Likes
Nige_S:
you should
yes that is great - thanks very much evanfuchs!
Ok great I will also take a look at this - many thanks for the suggestion.
Good stuff - thanks.
If I could get the Computer Name (in sharing prefs) - this will be different. Then I can use if / then logic...
I am trying to use :
set var computerName to %MacName%
if computerName contains MyOfficeMac
then ... xxx
It seems to work for what I need ... Is this the best way?
Nige_S
August 14, 2022, 5:38pm
7
It's simple and readable. Whether it's the best way depends on whether your computers' Sharing names ever change. If they do, or even might , then use the machine UUID instead: %MacUUID%
.
2 Likes
Thanks for all the help.
I am curious if there is a way to test if a second monitor is attached?
Thanks Much - I will check it out.
YES it works perfectly thanks.
1 Like