CGEvent does not work when the application is isolated

Here is a great post on how to press keys through code. Modeling CMD + Option + D in Cocoa

This works great, but when you download the application to the sandbox, it does not work. Does anyone know an exception that I have to request in the permissions file to make this work?

+4
source share
1 answer

I am sorry to report: there is not one (or at least there is no one that is not a temporary right). I asked Apple about this, and they said that this ability β€œdefeats the goal” of the application sandbox. If you want to do this without any temporary permission, the only way is to write the user an AppleScript file as follows:

tell application "System Events" keystroke "e" using {command down, option down, control down, shift down} end tell 

And then let it put this script in a specific folder so that you can run it using the NSUserAppleScriptTask API (this API is only 10.8). This, of course, is a mess and only an option in some cases ...

+1
source

Source: https://habr.com/ru/post/1485901/


All Articles