I am using a macro palette with "Show palette for one action when F13 is pressed" and it works very well. However I'd like the option to cancel/hide the palette by re-pressing its trigger key instead of having to press Esc to close it. Is this possible somehow?
My main reason for this is that I have this trigger key bound to a mouse button, and so it would be ideal to be able to also cancel the palette via mouse also.
As a workaround I thought I could use a separate macro that would close a palette by name, and I could use that to detect "if X palette is open, then F13 will close it" but I didn't see this option.
I do this with AppleScript that closes the palette if it already exists and returns a variable that tells the macro to cancel. If the variable is not returned, the macro continues and shows the palette instead.
Here's the AppleScript. Change "Test" the name of the palette.
tell application "System Events"
tell application process "Keyboard Maestro Engine"
if (first window whose subrole is "AXSystemDialog" and title is "Test") exists then
click button 1 of (first window whose subrole is "AXSystemDialog" and title is "Test")
return 1
end if
end tell
end tell
Just a note for anyone who like me couldn't get this to work initially: the palette needs the 'title' to be activated in order for the AppleScript to be able to click the close button.