MacOS – Open Preference Pane from command line on El Capitan (Mac OS X 10.11)

dockmacospreferences

I'm trying to open Preference Pane from command. However, when I invoke open /System/Library/PreferencePanes/Dock.prefPane as in
How do you access network preferences from the Terminal?, I get Finder that contains the preference pane opened instead.

What might be a way to open the preference pane? I also tried /System/Library/PreferencePanes/Dock.prefPane/Contents/MacOS/Dock to invoke the binary to have this error message.

-bash: /System/Library/PreferencePanes/Dock.prefPane/Contents/MacOS/Dock: cannot execute binary file

Best Answer

You can open System Preferences using its URL scheme:

open "x-apple.systempreferences:"

You can jump to a specific anchor on a specific pane using:

open "x-apple.systempreferences:com.apple.preference.keyboard?Text"

You can get the list of panes and anchors using AppleScript:

tell application "System Preferences"
    set myIds to the id of every pane
    set myAnchors to anchors of current pane
end tell 

Update: Apple has restricted use of the URL scheme in 10.11. As of this release only preference panes with NSPrefPaneAllowsXAppleSystemPreferencesURLScheme set in their Info.plist can be opened via the URL scheme.

Source: @Matt Stevens answer