如何在沙盒应用程序中使用辅助功能?

How to use Accessibility with sandboxed app?

OS X 有一个不错的功能,例如辅助功能 API,它允许从您的应用程序代码控制一些系统元素和其他应用程序。但它在打开 Sandbox 后停止工作。将应用程序提交到商店必须启用沙盒。

Apple 是这么说的:

With App Sandbox, you can and should enable your app for accessibility, as described in this document. However, you cannot sandbox an assistive app such as a screen reader, and you cannot sandbox an app that controls another app.

但 App Store 有一些应用程序使用辅助功能 API:

也就是说可以用Sandbox/Accessibility API/App 存储在一起,但是如何呢?

几年前,OS X 沙箱中还没有可访问性 API,但这可能已经改变了。然而,更有可能的是,这些应用程序设法从 Apple 获得了一个特殊的例外,并且它们有额外的沙盒权利,这些权利部分地将它们从沙盒中解脱出来,刚好足以让它们使用可访问性 API。

你应该做的是首先通过 bugreporter.apple.com 提交一个错误,告诉你你想用辅助功能做什么以及为什么,然后要求他们给你一个沙盒例外。如果他们批准例外,他们可能会为您提供一段自定义的沙箱配置文件语言代码,使您可以从(稍微弱化的)沙箱内调用可访问性 API。

话虽如此,但如果 Apple 说 "Sorry, that app doesn't fit the app store model. Please sign your app using Developer ID with sandboxing disabled, and distribute it outside the store."

,请不要感到惊讶,这取决于你在做什么

所有这些应用程序都是在 2012 年实施沙盒之前进入 App Store 的。我自己的 HazeOver 应用程序也是如此。它可以使用辅助功能只是因为它还没有沙盒化。 Apple 允许更新这些应用程序,但他们不会接受任何没有沙盒的新应用程序。