Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I automatically navigate users to System Preferences ➞ Privacy?

I know I can open the Security & Privacy preference pane like this:

open /System/Library/PreferencePanes/Security.prefPane

Is it possible to programmatically navigate to the Privacy tab? I want to make it easy for users to find the right screen. Note that the Accessibility API is disabled at the moment, that’s what I’m trying to enable on the Privacy tab. (This is a new feature in 10.9.)

like image 466
zoul Avatar asked Aug 08 '13 08:08

zoul


People also ask

What is a way Apple recommends to guard your Privacy on a Mac?

Set up a firewall If the firewall is on, you can also use “stealth mode,” which prevents your Mac from being discovered by others on the web. See Block connections to your Mac with a firewall. To set up and customize your firewall, use Network settings.

How to remove Privacy on Macbook?

In the Safari app on your Mac, use Privacy settings to remove and block data that websites can use to track you in Safari. To change these settings, choose Safari > Settings, then click Privacy. Periodically delete tracking data from third-party content providers, except for third-party content providers you visit.


1 Answers

I see from your answer to the other topic that you've already discovered AXProcessIsTrustedWithOptions, which will take the user straight to the privacy accessibility settings; you're presumably wanting to implement your own user prompt that is less baffling and suspicion-arousing than the official alert provided by that function.

You can open the Security & Privacy preferences pane and navigate straight to the Accessibility section using 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

One option is to save this to an applescript file with Applescript Editor and execute it directly:

osascript path/to/applescript.scpt

You can also perform the equivalent commands from your Objective C application code via the Scripting Bridge. This is a little more involved in that you need build an Objective C header (using Apple's commandline tools) that exposes the System Preferences scripting API as scriptable objects. (See Apple's Scripting Bridge documentation for details of how to build a header.)


Edit: Once you've built a System Preferences header, the following Objective C code will do the same work as the Applescript above:

//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];

Note however that (last I checked, at least) the Scripting Bridge is not usable by sandboxed applications.

like image 157
Alun Bestor Avatar answered Sep 24 '22 17:09

Alun Bestor