macos - 用于在沙盒环境中激活其他应用程序的菜单项的 CGEventPostToPSN() 替代方案?

标签 macos cocoa background sandbox appstore-sandbox

我有这个应用程序,我需要从我的应用程序中激活其他应用程序的菜单项(例如 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/

相关文章:

java - 如何修复 java 版本编码 "java_home: option requires an argument -- v"中的错误?

objective-c - 将 AppleScript 响应转换为 JSON

objective-c - 使用 NSPredicateEditor 编辑 NSPredicate

android - 在 AppTheme 中设置了 colorBackground 的 AppCompat Spinner 样式背景?

android - 服务中的关键倾听者

python - 使用多处理池时的 Pycharm 调试器

macos - 如何为Mac应用程序帮助创建.help文件?

c++ - 在 Mac OSX 上打包 C++ 守护程序的推荐方法是什么?

cocoa - 在 Cocoa 中处理模板选择器的最佳方法是什么

html - 如何从 DIV 背景中的 CSS Sprites 中选择所需的图像并对其进行定位?