I have created an automator workflow; then I have created a keyboard shortcut in the Keyboard Settings to run this as a Quick Action on a keypress.
All of this works. But the workflow seems to run in the security context of the application which was active when I pressed the hotkey.
The activity inside the service has nothing to do with the current application (it takes a screenshot and then does something with it); it doesn't access the "current" application in any way.
It needs to access the System Events, and thus security kicks in. I then have to enable access to those features for any application which happened to be in the foreground when I hit the hotkey.
Is it possible to avoid this - i.e. run my service in a context of its own?
EDIT for clarification: The workflow clicks menus of applications, and sends keystrokes.
... take a screenshot ... ... startup GIMP ... tell application "System Events" tell process "GIMP-2.10" ... click menu item "From Clipboard" of menu 1 of menu item "Create" of menu 1 of menu bar item "File" of menu bar 1 ... keystroke " " ...
As an example, say I press the hotkey while Emacs is in front. I then get a security prompt asking me to allow some security aspects for Emacs. I neither want do give Emacs any permissions, nor do I want to repeat this for any other application which might be in focus when I take a screenshot later.