I am looking for a way to write small apps for the sole purpose of launching individual KBM macros. The obvious way is to write a bit of Applescript then turn it into an app. Sometimes that works, but sometimes it doesn't. Specifically it fails if you tell KBM to simulate a keystroke.
My conclusion after a bunch of careful troubleshooting: An application needs root permission to trigger a keystroke action in a Keyboard Maestro macro. This is not true for all actions.
Consider two macros. "Test Display Text" consists of a Display Text action to put a few words on the screen. "Test Keystroke" consists of a Type the Keystroke action to simulate βN. These two macros are launched by two simple Applescripts, display.scpt, and keystroke.scpt.
display.scpt:
tell application "Keyboard Maestro Engine"
do script "Test Display Text"
end tell
keystroke.scpt:
tell application "Keyboard Maestro Engine"
do script "Test Keystroke"
end tell
Both of these work fine when run inside Script Debugger or when run from the command line using osascript.
But now save the two scripts as apps, display.app and keyboard.app. When clicked on in Finder or run with open -a in a command line, display.app works great. But keystroke.app fails, consistently, regardless of how it is executed.
The only way that I could find to turn a script into an app that would successfully execute the "Test Keystroke" macro was to build the application using Platypus and turn on the "run with root privileges" option. The problem there, of course, is that every time you run it you have to type in the root password, which sort of defeats the purpose.
Note that this really is about root privilege and not something in Accessibility. Apps that have been properly registered in System Preferences --> Security & Privacy --> Privacy --> Accessibility fail. But apps that have not been registered succeed when run with root privilege.
Just running an app with sudo open -a keystroke.app fails.
I'm running the current version of Catalina. Watching the console output, trying to execute an app that tells KBM to simulate a keystroke generates a ton of errors, most of which are related to the code being unsigned.
Any suggestions or insight would be appreciated. Again, my hope is to find a way to launch KBM macros -- in particular those that simulate keystrokes -- by running apps.