Add Support for System Preferences ⚙️

I was playing with hook to add support for System Preferences :gear: deep linking (which Apple calls them Anchors) here’s the result:

you can open System Preferences panes and anchors with this url scheme:

open "x-apple.systempreferences:com.apple.preferences.sharing?Services_ScreenSharing"

Notice it is x-apple.systempreferences: and not x-apple.systempreferences://
which currently Hook does not support as of version 3.1
So as a workaround we will add our own scheme

After the following steps you will be able to copy and open System Preferences Panes / Anchors (Deep Links) e.g. System Preferences → Spotlight (privacy)

  1. Add x-hook.systempreferences in Script Editor → Open Item → scheme

  2. Add the following script to Script Editor → Open Item

    //JavaScript
    
    const app = Application("System Preferences");
    app.includeStandardAdditions = true;
    app.activate();
    
    const [_, paneId, anchorId] = /(?::\/\/)([^?]+)?(?:\?(.*))?$/.exec("$0");
    
    const pane = paneId ? app.panes.byId(paneId) : null;
    const anchor = anchorId && pane ? pane.anchors.byName(anchorId) : null
    
    app.reveal(anchor || pane);
    
  3. Add the following script to Script Editor → Get Address

    //JavaScript
    /*
      Apple's URL Scheme: x-apple.systempreferences:com.apple.preferences.sharing?Services_ScreenSharing
      More Info: https://stackoverflow.com/a/24703872
    */
    
    const app = Application("System Preferences");
    app.includeStandardAdditions = true;
    
    const pane = app.currentPane();
    let anchor = pane ? app.chooseFromList(pane.anchors().map(a => a.name()), { withPrompt: 'Select an Anchor' }) : null;
    
    anchor = anchor && anchor.length > 0 && anchor[0] || "";
    let paneId = pane && pane.id() || "";
    let name = "System Preferences";
    name = pane ? `${name} → ${pane.name()}` : name;
    name = anchor ? `${name} (${anchor})` : name;
    `[${name}](x-hook.systempreferences://${paneId}?${anchor})`
    
3 Likes

Can you explain the use case scenario for this script? So you are deep linking to system preference panes?

Nothing special, It goes deeper than just panes…
The main use case for me is finding the anchors like: Privacy_Accessibility
in the System Preferences → Security & Privacy → Accessibility

also accessible with:

open "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility"
1 Like