MacOS – Give assistive access to a single applescript

applescriptitermmacosSecurityterminal

I have this script:

#!/usr/bin/env osascript
activate application "SystemUIServer"
tell application "System Events"
tell process "SystemUIServer" to keystroke "q" using {command down, control down}
end tell

It needs assistive access. It seems I have to enable this access for the whole terminal application (iTerm2 in my case) to get it to work. This seems like giving a lot of privilege to iTerm. What are the security implications? Is there a workaround?

Best Answer

"Is there a workaround?" I'd call it the "right" way.

Use the script editor. save the script as an application. Thus, the script becomes a full fledged application. Give the app assertive capabilities. should you want to start the app from the terminal, open your-app.

What to worry about: "Effective defenses against malware and other threats" by John Galt https://discussions.apple.com/docs/DOC-8841