システム設定ではなく、システム環境設定ってことは古いOSになってしまいますけど、動作させたいのはSonoma上でしょうか?
他の質問で解決されたと見かけたのですが、こんな感じでもどうでしょう?
接続先上で実行する必要があると思いますが、こんなAppleScriptで。
if application "System Settings" is running then
tell application "System Events"
tell process "システム設定"
tell application "System Settings" to activate
if (exists sheet 1 of window 1) then
key code 53
delay 0.8
end if
end tell
end tell
end if
tell application "System Settings"
reveal anchor "Services_ARDService" of pane id "com.apple.Sharing-Settings.extension"
activate
repeat until (exists window "共有")
delay 0.4
end repeat
end tell
activate application "System Settings"
tell application "System Events"
tell process "システム設定"
tell window "共有"
repeat until (exists sheet 1)
delay 0.4
end repeat
tell group 1 of scroll area 1 of group 1 of sheet 1
if ((get value of checkbox 1) as boolean) then
click checkbox 1
delay 2
click checkbox 1
delay 0.4
beep
delay 1
else
--click checkbox 1
end if
end tell
end tell
end tell
end tell