How to launch system preferences to a specific preference pane using bundle identifier?
Asked Answered
L

2

19

I'm trying to open the system date & time preferences directly from my app. I can seem to open System Preferences with no issue using:

let settingsBundleIdentifier = "com.apple.systempreferences"

NSWorkspace.shared.launchApplication(withBundleIdentifier: settingsBundleIdentifier, options: [], additionalEventParamDescriptor: nil, launchIdentifier: nil)

But I can't figure out how to go directly to the date & time pane.

I tried changing the bundle identifier to com.apple.systempreferences:com.apple.datetimepref and com.apple.systempreferences:com.apple.preference.datetime to no avail.

What should I be doing here? Can one not open the pane directly through the bundle identifier?

I'm aware that I can open the preference pane directly using file path to DateTime.prefPane. But I'm looking to open it using bundle identifiers.

Libelant answered 11/10, 2018 at 3:54 Comment(2)
Possible duplicate of Cocoa button opens a System Preference pagePosthorse
@Posthorse I can see that I can open it using file path as stated in the answer above. But was looking to see if I can open it directly with just the bundle identifier?Libelant
R
31

2023:

Any needed Preference Panes(.prefPane):

NSWorkspace.shared.open(URL(fileURLWithPath: "/System/Library/PreferencePanes/%PrefsNsme%.prefPane"))

replace %PrefsNsme% to any needed filename that is located at:

/System/Library/PreferencePanes/

systemPrefs:

NSWorkspace.shared.open(URL(string: "x-apple.systempreferences:com.apple.preference")!)

Some of the System Preferences are actually grouped as extensions, and called using this format:

NSWorkspace.shared.open(URL(string: "x-apple.systempreferences:com.apple.%ExtensionName%)!)

Extension list curated from:

/System/Applications/SystemSettings.app/Contents/Resources/Sidebar.plist

List of Extension URLs for reference [macOS Ventura]. Some use .extension some do not:

Family Settings: x-apple.systempreferences:com.apple.Family-Settings.extension
Software Update: x-apple.systempreferences:com.apple.FollowUpSettings.FollowUpSettingsExtension
Wifi: x-apple.systempreferences:com.apple.wifi-settings-extension
Bluetooth: x-apple.systempreferences:com.apple.BluetoothSettings
Network: x-apple.systempreferences:com.apple.Network-Settings.extension
Classroom Settings: x-apple.systempreferences:com.apple.ClassroomSettings
Classroom Settings2: x-apple.systempreferences:com.apple.Classroom-Settings.extension
Notifications: x-apple.systempreferences:com.apple.Notifications-Settings.extension
Sound: x-apple.systempreferences:com.apple.Sound-Settings.extension
Focus: x-apple.systempreferences:com.apple.Focus-Settings.extension
Screen Time: x-apple.systempreferences:com.apple.Screen-Time-Settings.extension
Appearance: x-apple.systempreferences:com.apple.Appearance-Settings.extension
Accessibility: x-apple.systempreferences:com.apple.Accessibility-Settings.extension
Control Center: x-apple.systempreferences:com.apple.ControlCenter-Settings.extension
Siri: x-apple.systempreferences:com.apple.Siri-Settings.extension
Spotlight: x-apple.systempreferences:com.apple.Spotlight-Settings.extension
Privacy Security: x-apple.systempreferences:com.apple.settings.PrivacySecurity.extension
Desktop: x-apple.systempreferences:com.apple.Desktop-Settings.extension
Displays: x-apple.systempreferences:com.apple.Displays-Settings.extension
Wallpaper: x-apple.systempreferences:com.apple.Wallpaper-Settings.extension
Screen Saver: x-apple.systempreferences:com.apple.ScreenSaver-Settings.extension
Battery: x-apple.systempreferences:com.apple.Battery-Settings.extension
Lock Screen: x-apple.systempreferences:com.apple.Lock-Screen-Settings.extension
Touch ID: x-apple.systempreferences:com.apple.Touch-ID-Settings.extension
Users Groups: x-apple.systempreferences:com.apple.Users-Groups-Settings.extension
Passwords: x-apple.systempreferences:com.apple.Passwords-Settings.extension
Passwords2: x-apple.systempreferences:com.apple.Passwords
Internet Accounts: x-apple.systempreferences:com.apple.Internet-Accounts-Settings.extension
Game Center: x-apple.systempreferences:com.apple.Game-Center-Settings.extension
Wallet: x-apple.systempreferences:com.apple.WalletSettingsExtension
Keyboard: x-apple.systempreferences:com.apple.Keyboard-Settings.extension
Mouse: x-apple.systempreferences:com.apple.Mouse-Settings.extension
Trackpad: x-apple.systempreferences:com.apple.Trackpad-Settings.extension
Game Controller: x-apple.systempreferences:com.apple.Game-Controller-Settings.extension
CD-DVD: x-apple.systempreferences:com.apple.CD-DVD-Settings.extension
Print Scan: x-apple.systempreferences:com.apple.Print-Scan-Settings.extension

List of URLs for reference [updated for macOS Ventura]:

Accessibility Preference Pane
Main    x-apple.systempreferences:com.apple.preference.universalaccess
Display x-apple.systempreferences:com.apple.preference.universalaccess?Seeing_Display
Zoom    x-apple.systempreferences:com.apple.preference.universalaccess?Seeing_Zoom
VoiceOver   x-apple.systempreferences:com.apple.preference.universalaccess?Seeing_VoiceOver
Descriptions    x-apple.systempreferences:com.apple.preference.universalaccess?Media_Descriptions
Captions    x-apple.systempreferences:com.apple.preference.universalaccess?Captioning
Audio   x-apple.systempreferences:com.apple.preference.universalaccess?Hearing
Keyboard    x-apple.systempreferences:com.apple.preference.universalaccess?Keyboard
Mouse & Trackpad    x-apple.systempreferences:com.apple.preference.universalaccess?Mouse
Switch Control  x-apple.systempreferences:com.apple.preference.universalaccess?Switch
Dictation   x-apple.systempreferences:com.apple.preference.universalaccess?SpeakableItems

Security & Privacy Preference Pane
Main    x-apple.systempreferences:com.apple.preference.security
General x-apple.systempreferences:com.apple.preference.security?General
FileVault   x-apple.systempreferences:com.apple.preference.security?FDE
Firewall    x-apple.systempreferences:com.apple.preference.security?Firewall
Advanced    x-apple.systempreferences:com.apple.preference.security?Advanced
Privacy x-apple.systempreferences:com.apple.preference.security?Privacy
Privacy-Camera x-apple.systempreferences:com.apple.preference.security?Privacy_Camera
Privacy-Microphone  x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone
Privacy-Automation  x-apple.systempreferences:com.apple.preference.security?Privacy_Automation
Privacy-AllFiles    x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles
Privacy-Accessibility   x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility
Privacy-Assistive   x-apple.systempreferences:com.apple.preference.security?Privacy_Assistive
Privacy-Location Services   x-apple.systempreferences:com.apple.preference.security?Privacy_LocationServices
Privacy-SystemServices  x-apple.systempreferences:com.apple.preference.security?Privacy_SystemServices
Privacy-Advertising x-apple.systempreferences:com.apple.preference.security?Privacy_Advertising
Privacy-Contacts    x-apple.systempreferences:com.apple.preference.security?Privacy_Contacts
Privacy-Diagnostics & Usage x-apple.systempreferences:com.apple.preference.security?Privacy_Diagnostics
Privacy-Calendars   x-apple.systempreferences:com.apple.preference.security?Privacy_Calendars
Privacy-Reminders   x-apple.systempreferences:com.apple.preference.security?Privacy_Reminders
Privacy-Facebook    x-apple.systempreferences:com.apple.preference.security?Privacy_Facebook
Privacy-LinkedIn    x-apple.systempreferences:com.apple.preference.security?Privacy_LinkedIn
Privacy-Twitter x-apple.systempreferences:com.apple.preference.security?Privacy_Twitter
Privacy-Weibo   x-apple.systempreferences:com.apple.preference.security?Privacy_Weibo
Privacy-Tencent Weibo   x-apple.systempreferences:com.apple.preference.security?Privacy_TencentWeibo

macOS Catalina 10.15:
Privacy-ScreenCapture   x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture
Privacy-DevTools    x-apple.systempreferences:com.apple.preference.security?Privacy_DevTools
Privacy-InputMonitoring x-apple.systempreferences:com.apple.preference.security?Privacy_ListenEvent
Privacy-DesktopFolder   x-apple.systempreferences:com.apple.preference.security?Privacy_DesktopFolder
Privacy-DocumentsFolder x-apple.systempreferences:com.apple.preference.security?Privacy_DocumentsFolder
Privacy-DownloadsFolder x-apple.systempreferences:com.apple.preference.security?Privacy_DownloadsFolder
Privacy-NetworkVolume   x-apple.systempreferences:com.apple.preference.security?Privacy_NetworkVolume
Privacy-RemovableVolume x-apple.systempreferences:com.apple.preference.security?Privacy_RemovableVolume
Privacy-SpeechRecognition   x-apple.systempreferences:com.apple.preference.security?Privacy_SpeechRecognition
Privacy-DevTools    x-apple.systempreferences:com.apple.preference.security?Privacy_DevTools

macOS Big Sur 10.11/10.16:
Privacy-Bluetooth   x-apple.systempreferences:com.apple.preference.security?Privacy_Bluetooth
Privacy-Music   x-apple.systempreferences:com.apple.preference.security?Privacy_Media
Privacy-Home    x-apple.systempreferences:com.apple.preference.security?Privacy_HomeKit


Dictation & Speech Preference Pane
Dictation   x-apple.systempreferences:com.apple.preference.speech?Dictation
Text to Speech  x-apple.systempreferences:com.apple.preference.speech?TTS
Sharing Preference Pane
Main    x-apple.systempreferences:com.apple.preferences.sharing
Screen Sharing  x-apple.systempreferences:com.apple.preferences.sharing?Services_ScreenSharing
File Sharing    x-apple.systempreferences:com.apple.preferences.sharing?Services_PersonalFileSharing
Printer Sharing x-apple.systempreferences:com.apple.preferences.sharing?Services_PrinterSharing
Remote Login    x-apple.systempreferences:com.apple.preferences.sharing?Services_RemoteLogin
Remote Management   x-apple.systempreferences:com.apple.preferences.sharing?Services_ARDService
Remote Apple Events x-apple.systempreferences:com.apple.preferences.sharing?Services_RemoteAppleEvent
Internet Sharing    x-apple.systempreferences:com.apple.preferences.sharing?Internet
Bluetooth Sharing   x-apple.systempreferences:com.apple.preferences.sharing?Services_BluetoothSharing

Software update x-apple.systempreferences:com.apple.preferences.softwareupdate?client=softwareupdateapp

macOS Monterey 12.0:
Privacy-DoNotDisturb    x-apple.systempreferences:com.apple.preference.security?Privacy_Focus

macOS Ventura 13.0:
Privacy-AppBundles    x-apple.systempreferences:com.apple.preference.security?Privacy_AppBundles
Privacy-ListenEvent    x-apple.systempreferences:com.apple.preference.security?Privacy_ListenEvent

Dictation & Speech Preference Pane
Dictation   x-apple.systempreferences:com.apple.preference.speech?Dictation
Text to Speech  x-apple.systempreferences:com.apple.preference.speech?TTS
Sharing Preference Pane
Main    x-apple.systempreferences:com.apple.preferences.sharing
Screen Sharing  x-apple.systempreferences:com.apple.preferences.sharing?Services_ScreenSharing
File Sharing    x-apple.systempreferences:com.apple.preferences.sharing?Services_PersonalFileSharing
Printer Sharing x-apple.systempreferences:com.apple.preferences.sharing?Services_PrinterSharing
Remote Login    x-apple.systempreferences:com.apple.preferences.sharing?Services_RemoteLogin
Remote Management   x-apple.systempreferences:com.apple.preferences.sharing?Services_ARDService
Remote Apple Events x-apple.systempreferences:com.apple.preferences.sharing?Services_RemoteAppleEvent
Internet Sharing    x-apple.systempreferences:com.apple.preferences.sharing?Internet
Bluetooth Sharing   x-apple.systempreferences:com.apple.preferences.sharing?Services_BluetoothSharing

Software update x-apple.systempreferences:com.apple.preferences.softwareupdate?client=softwareupdateapp

//https://mcmap.net/q/507263/-cocoa-button-opens-a-system-preference-page

More useful information about topic: https://github.com/bvanpeski/SystemPreferences/blob/main/macos_preferencepanes-Monterey.md

UPD:

Sonoma changed preference system so this may now work on Sonoma. Please doublecheck!

Roberts answered 30/11, 2019 at 21:13 Comment(5)
import AppKit ;)Zima
is there a way to dump the additional parameters? for example, how do i figure out additional parameters for the newly added Extensions.prefPane?Caulescent
@Caulescent you need to find the same list for monterey and to find needed string :) If you will find it -- please update my answer with it :)Roberts
Is it allowed to use such keys? From my readings, these are Apple's private keys which the apps are not allowed to use.Anagnorisis
@Anagnorisis yep, it's just an URLs that is accessible from OS.Roberts
F
6

I found the following code to open the Security PrefPane to a certain page:

    let prefpaneUrl = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility")!
    NSWorkspace.shared.open(prefpaneUrl)

but oddly, when I try the same for Date & Time

    let prefpaneUrl = URL(string: "x-apple.systempreferences:com.apple.preference.datetime"
    NSWorkspace.shared.open(prefpaneUrl)

it doesn't work, nor if I use the bundle identifier of the Date & Time PrefPane:

    let prefpaneUrl = URL(string: "x-apple.systempreferences:system.preferences.datetime")!
    NSWorkspace.shared.open(prefpaneUrl)

Update: There is a list of working pref pane identifiers here: http://web.archive.org/web/20190606022433/https://macosxautomation.com/system-prefs-links.html Seems Date & Time just isn't exposed.

Frail answered 12/6, 2019 at 19:7 Comment(2)
Dang, bluetooth is not exposed :/ thanks for the link though!Ostler
@AlexPera I reverted your edit. Please do not just change links in answers to different sites. It makes it look like a site was endorsed by the original poster. If a link goes dead, either replace it with a web archive link, or leave a comment with your different, working link.Frail

© 2022 - 2024 — McMap. All rights reserved.