我有这个应用程序,我需要从我的应用程序中激活其他应用程序的菜单项(例如 Print cmd+p)。现在我正在使用 CGEventPostToPSN() 来完成这项工作,它工作正常,但是当我激活沙箱时,它停止工作。
CGEventPostToPSN(&psn, keyDownEvent);
CFRelease(keyDownEvent);
CGEventPostToPSN(&psn, keyUpEvent);
CFRelease(keyUpEvent);
我现在的问题是,当我需要启用沙箱时我该怎么办?我听说过很多有关 Accessibility API 的信息,但我无法找到如何激活其他应用程序的菜单项。我很感谢有关此问题的任何答案。
法比安
最佳答案
在沙盒环境中,您仍然可以将 Apple 事件发送到其他应用程序 - 您只需为您的应用程序申请“Apple 事件临时异常(exception)”即可。 Apple 的 Element Key Reference 对此进行了详细说明。在“Apple 事件临时异常(exception)”部分中。
Apple Event Temporary Exception
When you adopt App Sandbox, your app retains the ability to:
● Receive Apple events
● Send Apple events to itself
● Respond to Apple events it receives
However, with App Sandbox you cannot send Apple events to other apps unless you configure the apple-events temporary exception entitlement.For each app you want to send Apple events to, specify the app’s bundle identifier, in all lowercase characters, as a string value for this entitlement key’s value array. For example, to enable sending Apple events to iPhoto from your app, use the string value com.apple.iphoto.
Entitlement key Capability
com.apple.security.temporary-exception.apple-events
Enables sending of Apple events to one or more destination apps.
据我所知,Apple 尚未在这种情况下明确定义“临时”,但共识是 Apple 暂时允许,但 future 的一些应用程序商店或 Mac OS X更新可能会删除执行此操作的功能。
请注意,您必须提前明确声明您需要能够将事件发送到的应用程序,这不能在运行时由您的应用程序或用户动态选择。
关于macos - 用于在沙盒环境中激活其他应用程序的菜单项的 CGEventPostToPSN() 替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7993062/