Please select the date or the clock in the menu bar. The background remains the same. Then use the left arrow on flux. Use the down arrow key to go to your menu command.
The whole stuff with “timeout” and “killall System Events” was necessary because of a strange delay caused by the first AXPress. I didn’t find a better way to work around it. Credits to Aviral Bansal for the ‘killall’ idea.
In case you modify the script, attention with the ellipsis in “Preferences...”: these are three separate dots, not the ellipsis character.
If it doesn’t work set the timeout to 0.2 or 0.3, etc.
Instead of the combination of “try” and “timeout” you could also use “ignoring application results”, but this worked for me only in a standalone script (launched from SD or FastScripts), but not via KM.
It shouldn’t be a problem. This works for me on my macOS 10.12.2 system.
With this sort of brute-force approach timing issues are likely, and it may be necessary to use pauses appropriately to let the UI catch up to Keyboard Maestro.
Nope. Weird. I tried your macro and it’s the same as with my macro above: It works only with the try & timeout in the AppleScript:
tell application "System Events"
tell application process "Flux"
tell menu bar 1
tell menu bar item 1
try
with timeout of 0.1 seconds
perform action "AXPress"
end timeout
end try
end tell
end tell
end tell
end tell
The “ignoring” version does not open the menu. (But it does when launched from SD.)
KM 7.3.1 and OS 10.12.3 Beta (16D30a) here.
Maybe the 10.12.3 makes the difference, but I don’t really believe. Maybe some differences in KM’s settings?
System Events was unchecked in the Accessibility Privacy settings:
Now also in KM both methods work. I have no clue why and since when it was unchecked. And the weird thing is that all of my other UI scripts were working, and that it affected the “ignoring application responses” only when launched from KM.
I would like to experiment with this shell script "killall System\ Events" but i can't find the script itself nowhere. Maybe i am overlooking something obvious, but i guess i have to install it in /usr/local/bin/, right?
The thingy in-between the double quotes is the shell script:
killall 'System Events’
With the AppleScript command do shell script you can either run a script that is directly contained in the AppleScript, like in…
do shell script "killall 'System Events'"
…or a script that is stored as external file, like in…
do shell script "/path/to/my/scriptfile.sh"
In other words, if the content of the “scriptfile.sh” file is killall 'System Events', then both of the above should have the same result. (Assuming “scriptfile.sh” is executable.)