Question

Here's a great post on how to press keys through code. CMD+Option+D simulation in Cocoa

This works great but when you sandbox the app, it doesn't work. Does anyone know the exception I should request in the entitlement file to make this work?

Was it helpful?

Solution

I'm sorry to report: there isn't one (or at least there isn't one that isn't a temporary entitlement). I asked Apple about this specifically and they said that this ability "defeats the purpose" of app sandboxing. If you want to do this without any temporary entitlement the only way is to have the user write an AppleScript file like this:

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top