「システム設定」の指定したPaneの表示を行う(第2階層まで選択可)

macOS Venturaで搭載された「システム設定」アプリを操作するスクリプトです。第2階層まで選択できるようにしています。

--すべてのPane名とインデックス番号を返す。初回のみ下記の「--return get_settings_list()」のコメントタグを外し、実行することで一覧のリストが表示される。Pane名をそこからコピーすることで間違いをなくせるのでコピペ推奨。
--return get_settings_list()
-->{{"(氏名), Apple ID", 2}, {"ファミリー", 3}, {"Wi‑Fi", 5}, {"Bluetooth", 6}, {"ネットワーク", 7}, {"通知", 9}, {"サウンド", 10}, {"集中モード", 11}, {"スクリーンタイム", 12}, {"一般", 14}, {"外観", 15}, {"アクセシビリティ", 16}, {"コントロールセンター", 17}, {"SiriSpotlight", 18}, {"プライバシーとセキュリティ", 19}, {"デスクトップとDock", 21}, {"ディスプレイ", 22}, {"壁紙", 23}, {"スクリーンセーバ", 24}, {"省エネルギー", 25}, {"ロック画面", 27}, {"ログインパスワード", 28}, {"ユーザとグループ", 29}, {"パスワード", 31}, {"インターネットアカウント", 32}, {"Game Center", 33}, {"キーボード", 35}, {"マウス", 36}, {"トラックパッド", 37}, {"CDDVD", 38}, {"プリンタとスキャナ", 39}, {"macFUSE", 41}, {"カーソルセンス", 42}, {"ステアーマウス", 43}}

open_settings_to("Bluetooth", {groupNumber:0, buttonNumber:0})
open_settings_to("コントロールセンター", {groupNumber:0, buttonNumber:0})
--open_settings_to("(氏名), Apple ID", {groupNumber:3, buttonNumber:1})
open_settings_to("ファミリー", {groupNumber:2, buttonNumber:3})
open_settings_to("プライバシーとセキュリティ", {groupNumber:1, buttonNumber:12})
open_settings_to("外観", {groupNumber:0, buttonNumber:0})
open_settings_to("集中モード", {groupNumber:1, buttonNumber:1})
open_settings_to("一般", {groupNumber:1, buttonNumber:1})
open_settings_to("Wi‑Fi", {groupNumber:1, buttonNumber:1})
open_settings_to("ユーザとグループ", {groupNumber:1, buttonNumber:1})
open_settings_to("トラックパッド", {groupNumber:0, buttonNumber:0})
open_settings_to("省エネルギー", {groupNumber:0, buttonNumber:0})


--システム設定で、指定したPaneを選択し、右画面のボタンを押すためのグループ番号とボタンナンバーを渡す
on open_settings_to(settings_pane, {groupNumber:groupNum, buttonNumber:buttonNum})

--システム設定アプリの起動状態チェック
script SC
on check_if_the_startup_is_completed()
activate application "System Settings"
tell application "System Events"
tell process "System Settings"
set aNum to 0
repeat 100 times
delay 0.2
set aNum to aNum + 1
if aNum is 100 then return false
if exists window 1 then
return true
end if
end repeat
end tell
end tell
end check_if_the_startup_is_completed
end script

--右画面のボタンを押す
script cB
on clickButton(groupNum, buttonNum)
activate application "System Settings"
if groupNum = 0 and buttonNum = 0 then return
tell application "System Events"
tell application process "System Settings"
tell scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window 1
if exists (get every group) then
if exists (get every button) then
click button buttonNum of group groupNum
delay 1.5
end if
end if
end tell
end tell
end tell
end clickButton
end script

--指定したPaneを選択
if (check_if_the_startup_is_completed() of SC) then
tell application "System Events"
tell application process "System Settings"
if exists (sheet 1 of window 1) then
key code 53
delay 0.2
end if
set row_num to 0
set wName to name of static text 1 of window 1
tell window 1
tell outline 1 of scroll area 1 of group 1 of splitter group 1 of group 1
set everyRowName to get value of static text 1 of UI element 1 of rows
repeat with i in everyRowName
set row_num to row_num + 1
if (contents of i) is settings_pane then
if selected of row row_num then
if wName is not (contents of i) then
if selected of row 5 then
select row 6
delay 0.2
select row row_num
else
select row 5
delay 0.2
select row row_num
end if
end if
else
select row row_num
end if

tell application "System Events"
tell application process "System Settings"
if settings_pane ends with "Apple ID" then
set settings_pane to text 1 thru ((offset of "," in settings_pane) - 1) of settings_pane
end if
repeat 100 times
delay 0.2
if (name of static text 1 of window 1) is settings_pane then exit repeat
end repeat
end tell
end tell

delay 0.3
try
clickButton(groupNum, buttonNum) of cB
exit repeat
on error msg
beep
display alert msg
return
end try
end if
end repeat
end tell
end tell
end tell
end tell
end if
end open_settings_to


--システム設定の各Paneの名称とインデックス番号を返す
on get_settings_list()

script SC
on check_if_the_startup_is_completed()
activate application "System Settings"
tell application "System Events"
tell process "System Settings"
set aNum to 0
repeat 100 times
delay 0.2
set aNum to aNum + 1
if aNum is 100 then return false
if exists window 1 then
--display alert "起動完了!"
return true
end if
end repeat
end tell
end tell
end check_if_the_startup_is_completed
end script

if (check_if_the_startup_is_completed() of SC) then
tell application "System Events"
tell application process "System Settings"
set row_list to {}
set row_num to 0

tell window 1
tell outline 1 of scroll area 1 of group 1 of splitter group 1 of group 1
set everyRowName to get value of static text 1 of UI element 1 of rows
repeat with i from 1 to (length of everyRowName)
set row_num to row_num + 1
if (item i of everyRowName) is not missing value then
set row_name to item i of everyRowName
set val to {row_name, row_num}
copy val to end of row_list
end if
end repeat
end tell
end tell
end tell
end tell
return row_list
end if
end get_settings_list

更新履歴

inserted by FC2 system