I have this app where I need to activate an other app’s menu item (like Print cmd+p) from within my app. Right now I’m using CGEventPostToPSN() to do the job and it works fine, but when I activate sandboxing, it stops working.
CGEventPostToPSN(&psn, keyDownEvent);
CFRelease(keyDownEvent);
CGEventPostToPSN(&psn, keyUpEvent);
CFRelease(keyUpEvent);
My question now is what can I do when I need to enable sandboxing? I heard a lot about the Accessibility API but I was unable to find out how I can activate an other app’s menu item. I’m thankful for any answer on this problem.
Fabian
I still don’t have a final answer to this question, but it seems to be possible with the Accessibility API as suggested by @nielsbot.
There are some promising functions like
AXUIElementPostKeyboardEvent()andAXUIElementPerformAction(). Problem: Using the Accessibility API to control another app is prohibited in Apple’s Sandbox Guideline.If you came across this question and have the same problem as me, I fear you’re out of luck. Reconsider if you really have to control another app and if so, you might not be able to distribute your app on the Mac App Store, sorry.
Fabian