I would like enable AppleScript to reveal a particular tab within a custom preference pane I am developing, so that this works:
tell application "System Preferences"
reveal anchor "Foo" of pane id "com.example.preferences.Bar"
end tell
I cannot find anywhere how my preference pane would declare or specify the "Foo"
anchor or associate that with any particular tab view item.
For anyone that comes to this question with the amount of frustration I did, I'm documenting here the steps to be able to get anchors for your custom
NSPreferencePane
.The greatest hint was from @geowar:
I overlooked this comment the first time I came to this question, the second time I looked at the
GPGPreferences.m
file, more specifically therevealElementForKey
method but couldn't figure out how the function actually got called.The keyword was
searchTerms
.I only realized this when I finally found this article SearchablePreferencePanes.
Steps:
NSPrefPaneSearchParameters
key to theInfo.plist
of your preference pane bundle with a value something likeMyPreferencePane
.MyPreferencePane.searchTerms
in your Xcode project. The contents of this file should be a property list containing a dictionary that looks something like the one below (taken from theSound
preference pane). This will not only allow users to get a hit for your preference pane when searching for the specified terms, but it will also generate the anchors for the preference pane.revealElementForKey(key: String)
method in your class that inherits fromNSPreferencePane
. This method will be called both when the user opens the pane after searching for a term and also when calling thereveal()
method for the ScriptingBridge anchor class.Enjoy life.