Я вижу от your answer to the other topic, что вы уже обнаружили AXProcessIsTrustedWithOptions
, что приведет пользователя прямо к настройкам конфиденциальности; вы, по-видимому, хотите реализовать свою собственную подсказку пользователя, которая менее озадачивает и вызывает подозрение, чем the official alert provided by that function.
Вы можете открыть панель безопасности & предпочтения конфиденциальности и перейти прямо к разделу Accessibility с помощью Applescript:
tell application "System Preferences"
--get a reference to the Security & Privacy preferences pane
set securityPane to pane id "com.apple.preference.security"
--tell that pane to navigate to its "Accessibility" section under its Privacy tab
--(the anchor name is arbitrary and does not imply a meaningful hierarchy.)
tell securityPane to reveal anchor "Privacy_Accessibility"
--open the preferences window and make it frontmost
activate
end tell
Один из вариантов, чтобы сохранить это на AppleScript файл с AppleScript Editor и выполнить его непосредственно:
osascript path/to/applescript.scpt
Вы также можете выполнить эквивалентные команды из кода приложения Objective C с помощью скриптового моста. Это немного больше связано с тем, что вам нужно построить заголовок Objective C (используя инструменты командной строки Apple), который предоставляет API сценариев системных настроек как объекты сценариев. (См Apple's Scripting Bridge documentation подробной информации о том, как построить заголовок.)
Edit: После того, как вы создали заголовок Системных настроек, следующий код Objective C будет делать ту же работу, что и Applescript выше:
//Get a reference we can use to send scripting messages to System Preferences.
//This will not launch the application or establish a connection to it until we start sending it commands.
SystemPreferencesApplication *prefsApp = [SBApplication applicationWithBundleIdentifier: @"com.apple.systempreferences"];
//Tell the scripting bridge wrapper not to block this thread while waiting for replies from the other process.
//(The commands we'll be sending it don't have return values that we care about.)
prefsApp.sendMode = kAENoReply;
//Get a reference to the accessibility anchor within the Security & Privacy pane.
//If the pane or the anchor don't exist (e.g. they get renamed in a future OS X version),
//we'll still get objects for them but any commands sent to those objects will silently fail.
SystemPreferencesPane *securityPane = [prefsApp.panes objectWithID: @"com.apple.preference.security"];
SystemPreferencesAnchor *accessibilityAnchor = [securityPane.anchors objectWithName: @"Privacy_Accessibility"];
//Open the System Preferences application and bring its window to the foreground.
[prefsApp activate];
//Show the accessibility anchor, if it exists.
[accessibilityAnchor reveal];
Обратите внимание, однако, что (последний раз я проверил, по крайней мере), скриптовый мост не может использоваться в песочнице.
Спасибо! Да, я стараюсь избегать глупого системного диалога, который просто перенаправляет пользователя в Системные настройки без добавления какого-либо значения, кроме одного дополнительного нажатия кнопки и некоторого страшного текста, который все пользователи просто игнорируют. – zoul