Hello,
I'm trying to use AppleScript to click the KM status bar menu item.
I don't know how to click the third level menu item yet. But with the code I already have, there is a problem. The first click is quick, but the 2nd click happens quite a few seconds later. I don't know why.
Here is the code:
tell application "System Events" to tell process "Keyboard Maestro Engine"
click menu bar item 1 of menu bar 2
tell menu bar item 1 of menu bar 2
click menu item "Global Macro Group" of menu 1
end tell
end tell
Thanks, Chris. @peternlewis, do you have any thoughts about it?
I was trying to make it to work for a specific need.
I have customized the palette in the macro group settings and would like to trigger the palette with a script. I don't know any other way except simulating click on status menu entries.
Or, a better solution, is it possible to add a script trigger here?
I saw it before but did not make it to work. I thought it wasn't the solution I was looking for. But after some attempts, it's working now.
I got the idea from here (including the status menu bar click):
There is a bug where clicking some status menu items causes scripts to be blocked for about 5 seconds. One workaround is to terminate System Events after the click command:
launch application "System Events"
delay 0.2
ignoring application responses
tell application "System Events" to tell process "Time Tracker"
click menu bar item 1 of menu bar 2
end tell
end ignoring
do shell script "killall System\\ Events"
delay 0.1
tell application "System Events" to tell process "Time Tracker"
tell menu bar item 1 of menu bar 2
click menu item 2 of menu 1
end tell
end tell
The only adjustment I needed to make is to switch the delay 0.1 and do shell script ... from
-- this will not work.
do shell script "killall 'System Events'"
delay 0.1
To
-- this works.
delay 0.1
do shell script "killall 'System Events'"
Here is the complete AppleScript code:
ignoring application responses
tell application "System Events"
tell process "Keyboard Maestro Engine"
click menu bar item 1 of menu bar 2
end tell
end tell
end ignoring
delay 0.1
do shell script "killall 'System Events'"
tell application "System Events" to tell process "Keyboard Maestro Engine"
tell menu bar item 1 of menu bar 2
click menu item "Text Manipulation [Macro Group]" of menu 1
end tell
end tell
Also, because I don't know how to simulate clicking the status menu bar item at the second level, I can only to click the status menu bar item at the first level, I need to set the items either "By Group" or "Alphabetically".
Thanks, Chris.
It works great! Mine was not only too slow, it sometimes did not click the correct menu item when the cursor was inside the would-dropdown-menu area. Your macro does not have this issue.