Scripting System Settings under Ventura

I’ve been working to update my system settings script to work with Ventura without much success. My Google research returned a suggestion from Shane, which works well but does not work with anchors. A simple example:

use framework "AppKit"
use framework "Foundation"
use scripting additions

set thePreferences to {|General|:"com.apple.systempreferences.GeneralSettings", |Displays|:"com.apple.preference.displays", |Keyboard|:"com.apple.preference.keyboard", |Privacy & Security|:"com.apple.settings.PrivacySecurity.extension"}
set thePreferences to current application's NSDictionary's dictionaryWithDictionary:thePreferences
set preferencesNames to ((thePreferences's allKeys())'s sortedArrayUsingSelector:"localizedStandardCompare:") as list

set thePreference to item 1 of (choose from list (preferencesNames as list) default items {item 1 of preferencesNames})
set thePreference to "x-apple.systempreferences:" & (thePreferences's valueForKey:thePreference)
current application's NSWorkspace's sharedWorkspace()'s openURL:(current application's NSURL's URLWithString:thePreference)

An alternative to the above is to use the shell:

do shell script "open x-apple.systempreferences:com.apple.Date-Time-Settings.extension"

However, scripting System Settings directly fails in every instance:

tell application "System Settings"
	activate
	set theCurrentPane to current pane
	set thePaneName to name of current pane
	reveal pane id "com.apple.systempreferences.GeneralSettings"
end tell
-- all of the above --> System Settings got an error: AppleEvent handler failed.

Perhaps I got some simple syntax wrong or maybe System Settings is just broken for now. Anyone get this to work? Thanks

BTW, GUI scripting does work but that’s not what I’m interested in.

tell application id "com.apple.systempreferences"
	activate
	set theCurrentPane to current pane
	set thePaneName to name of current pane
	reveal pane id "com.apple.systempreferences.GeneralSettings"
end tell

or,

tell application "System Preferences"
	activate
	set theCurrentPane to current pane
	set thePaneName to name of current pane
	reveal pane id "com.apple.systempreferences.GeneralSettings"
end tell

KniazidisR. Thanks for the suggestions but both return an error:

AppleScript Execution Error
System Settings got an error: AppleEvent handler failed.
[0x0,69f69f “System Settings”]

Why do you tell to System Settings instead of System Preferences?

I believe it’s called System Settings in Ventura. At least, that’s the name shown in the Applications folder and the dictionary shows “System Settings.sdef”. Although, Finder shows the id of “System Settings.app” as “com.apple.systempreferences”. Whichever the case, neither seems to work. The following does work, though:

tell application "System Settings" to activate

Have you tried Raw (Chevron) syntax?

set revealAnchorScript to "tell «class capp» ID \"com.apple.systempreferences\" to set panesNamesList to «property pnam» of panes
set selectedPreference to («event gtqpchlt» panesNamesList given «class inSL»:{«class cobj» 15 of panesNamesList}, «class appr»:\"Select Pane Name\")
if selectedPreference = false then error number -128
set selectedPreference to «class cobj» 1 of selectedPreference

tell «class capp» ID \"com.apple.systempreferences\"
	set anchorNamesList to «property pnam» of anchors of «class xppb» selectedPreference
	set selectedAnchor to («event gtqpchlt» anchorNamesList given «class inSL»:{«class cobj» 1 of anchorNamesList}, «class appr»:\"Select Anchor Name\")
	if selectedAnchor = false then error number -128
	set selectedAnchor to «class cobj» 1 of selectedAnchor
	«event miscmvis» «class xppa» selectedAnchor of «class xppb» selectedPreference
end tell
"

run script revealAnchorScript

KniazidisR. Thanks but that returns the same error.

Perhaps the answer is that panes and anchors are no longer supported. In preliminary testing the following is an example that gets me part way to where I want to be:

do shell script "open x-apple.systempreferences:com.apple.preference.security?Privacy_Contacts"

There’s a good list of different settings here

FWIW, I’ve included below the script I will use for now to open System Settings in Ventura. The if statement is a bit long, but that makes the script easy to edit and allows the user to call a handler with GUI scripting if desired. The preference values can be obtained from the link in post 6 above.

To test this script, simply open it in a script editor on a Ventura computer and run. The script creates a small plist file in the user’s preferences folder.

-- use with Ventura only
use framework "Foundation"
use scripting additions

on main()
	set preferenceNames to {"Accessibility", "Desktop & Dock", "Displays", "General", "Keyboard", "Mouse", "Notifications"}
	set thePreference to readPlist() as text
	if thePreference is "missing value" then set thePreference to item 1 of preferenceNames
	set thePreference to (choose from list preferenceNames default items thePreference)
	if thePreference is false then error number -128
	set thePreference to item 1 of thePreference
	
	if thePreference is "Accessibility" then
		set preferenceValue to "x-apple.systempreferences:com.apple.Accessibility-Settings.extension"
	else if thePreference is "Desktop & Dock" then
		set preferenceValue to "x-apple.systempreferences:com.apple.Desktop-Settings.extension"
	else if thePreference is "Displays" then
		set preferenceValue to "x-apple.systempreferences:com.apple.Displays-Settings.extension"
	else if thePreference is "General" then
		set preferenceValue to "x-apple.systempreferences:com.apple.systempreferences.GeneralSettings"
	else if thePreference is "Keyboard" then
		set preferenceValue to "x-apple.systempreferences:com.apple.Keyboard-Settings.extension"
	else if thePreference is "Mouse" then
		set preferenceValue to "x-apple.systempreferences:com.apple.Mouse-Settings.extension"
	else if thePreference is "Notifications" then
		set preferenceValue to "x-apple.systempreferences:com.apple.Notifications-Settings.extension"
	end if
	
	do shell script "open " & preferenceValue
	writePlist(thePreference)
	delay 0.5
end main

on readPlist()
	set theDefaults to current application's NSUserDefaults's alloc()'s initWithSuiteName:"com.peavine.SystemSettings"
	return theDefaults's objectForKey:"theKey"
end readPlist

on writePlist(theValue)
	set theDefaults to current application's NSUserDefaults's alloc()'s initWithSuiteName:"com.peavine.SystemSettings"
	theDefaults's setObject:theValue forKey:"theKey"
end writePlist

main()

For what it’s worth, to use as an example, here’s an example that works fine:

tell application "System Preferences"
	activate
	tell application "System Events"
		tell dock preferences to set autohide menu bar to true
	end tell
	delay 1
	quit
end tell
3 Likes

Thanks ikenassi. I had forgotten that System Events has preferences suites, and they do still work under Ventura. I tried a few additional dock settings and they worked as expected. Apparently you don’t need to load System Settings if you don’t want to. Very nice :slight_smile:

tell application "System Events" to tell dock preferences
	set autohide to false -- applies to dock
	set dock size to 1.0
end tell
1 Like

You’re very welcome.

Scripting System Settings has been fixed in Ventura 13.3. The following did not work but does now:

tell application "System Settings"
	activate
	set theCurrentPane to current pane --> pane id "com.apple.systempreferences.GeneralSettings"
	set thePaneName to name of current pane --> "General"
	reveal pane id "com.apple.systempreferences.GeneralSettings" -- works as expected
	-- reveal pane id "com.apple.Appearance-Settings.extension" -- works as expected
end tell

You can also get anchors:

tell application "System Settings"
	activate
	set paneID to id of current pane --> "com.apple.Sound-Settings.extension"
	set anchorNames to name of every anchor of pane id paneID --> {"balance", "effects", "input", "mute", "output", "volume"}
end tell

And set anchors:

tell application "System Settings"
	activate
	reveal anchor "input" of pane id "com.apple.Sound-Settings.extension" -- works as expected
end tell
2 Likes

Thank you! I have been searching all over for this information!
How can I find out the anchor name for the ‘Alert volume’ slider?

FYI, I’m trying to build an AppleScript as part of a Keyboard Maestro macro that activates System Events so that I can type characters with no apparent effect, but I want to temporarily mute the system beep.

This works well in Utilities/Applescript in Automator to bring up the General panel, great work Thanks!

I found this other code that works in Utilities/Shell Script in Automator to bring up the Sharing Settings

‘open x-apple.systempreferences:com.apple.Sharing-Settings.extension’
https://gist.github.com/rmcdongit

This is where I want to be but I haven’t found the code to check to see if the selections are toggled on and toggle them on if they are not.

My purpose is to overcome an issue that has come up when I try to share with a remote iMac running Ventura after it has shut down and restarted or sometimes after it wakes from sleep, the toggles are all set to off. I need them to be correctly set after a restart.

Any ideas where that type of code would reside is appreciated. My apologies for ‘borrowing’ yours and others code

Edit: Hi

To clarify it appears to maintain the chosen sharing options after waking from sleep but reverts to all sharing toggled off when powering on.
I have a solution that works. I use “pmset repeat wakeorpoweron” to wake or power on before my morning starts. I created an app that manipulates the System Settings. It is selected to opens on startup and selected in Privacy & Security/Accessability.
I can post the script (The app is an AppleScript but a Shell Script works) or PM to anyone interested. I have to go through the bookmarks to ensure to proper references, a lot of work was done by others I am obliged to recognize.