8

次のように [セキュリティとプライバシー] 設定ペインを開くことができることを知っています。

open /System/Library/PreferencePanes/Security.prefPane

プログラムで [プライバシー] タブに移動することはできますか? ユーザーが適切な画面を簡単に見つけられるようにしたい。アクセシビリティ API は現在無効になっていることに注意してください。これを [プライバシー] タブで有効にしようとしています。(これは10.9 の新機能です。)

4

1 に答える 1

8

あなたがすでに発見した他のトピックへの回答からAXProcessIsTrustedWithOptionsユーザーはプライバシーのアクセシビリティ設定に直接移動します。おそらく、その関数によって提供される公式のアラートよりも困惑したり疑惑を引き起こしたりしない独自のユーザープロンプトを実装したいと考えています。

[セキュリティとプライバシー] 設定ペインを開き、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

1 つのオプションは、これを Applescript Editor で Applescript ファイルに保存し、直接実行することです。

osascript path/to/applescript.scpt

Scripting Bridge を介して、Objective C アプリケーション コードから同等のコマンドを実行することもできます。これは、システム設定スクリプト API をスクリプト可能なオブジェクトとして公開する Objective C ヘッダーを (Apple のコマンドライン ツールを使用して) 作成する必要があるという点で、もう少し複雑です。(ヘッダーの作成方法の詳細については、Apple の Scripting Bridge のドキュメントを参照してください。)


編集:システム設定ヘッダーを作成したら、次の 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];

ただし、(少なくとも最後に確認した限りでは) Scripting Bridge はサンドボックス化されたアプリケーションでは使用できないことに注意してください。

于 2013-10-05T11:43:00.777 に答える