I have a macOS Shortcut assigned to a global hotkey. One step runs this AppleScript:
tell application "System Events"
keystroke "c" using {control down, command down}
end tell
Goal: trigger ⌃⌘C globally, regardless of the front app.
Issue: each time it runs, macOS prompts me to grant Accessibility access to the current frontmost app (as if that app is sending the keystrokes, such as “Mail”). Accessibility is already enabled for both Shortcuts and System Events.
Is there a way to have only Shortcuts/System Events act as the sender to avoid these per-app prompts, or is this simply how it works? Any workarounds are welcome.
Try saving these AppleScript statements as an applet and have the Shortcut launch that. If that works for you, add the LSBackgroundOnly key to the applet’s Info.plist and set it to YES. That way, you won’t even notice the applet launching since it’ll run in the background and quit. It’s been a while since I’ve done this myself, so I hope there aren’t any security features that would block this approach.
1 Like
yes this worked, but it make it very hard to change later on because the AppleScript is not contained inside the Shortcut
You could save the statements in a text variable, save them to an .applescript file, then use osacompile
to turn it into an applet. After that, modify the Info.plist with defaults write
to make the applet run and quit in the background.
If you use the MD5 checksum of the original statements string as the filename for the applet and check for its existence first, you’ll have a caching system that skips the compilation step unless the AppleScript code actually changes.