ホットコーナーを設定する

ホットコーナーを設定するAppleScriptです。
Dockを初期化するとホットコーナーの設定もリセットされるため、再設定を楽にするものです。

if application "System Preferences" is running then -- スクリプト実行開始時にシステム環境設定が起動しているかどうか
set confirmStartup to true -- 起動しているから“true”
set curPaneID to getCurPaneID() of me -- 開いているペインのIDを取得
else
set confirmStartup to false -- 起動していないから“false”
end if

tell application "System Preferences"
reveal anchor "Main" of pane id "com.apple.preference.expose"
activate
delay 0.5
end tell

tell application "System Events"
tell process "システム環境設定"
tell window "Mission Control"

if not (exists sheet 1) then -- sheet 1 が開かれてなかったら、ホットコーナー…”を押す
click button "ホットコーナー…"
delay 0.3
end if

clickMenuItem("スクリーンセーバを開始する", 2) of me
clickMenuItem("通知センター", 4) of me
clickMenuItem("ディスプレイをスリープさせる", 3) of me

click button "OK" of sheet 1
delay 0.3

end tell
end tell
end tell

if confirmStartup is false then
quit application "System Preferences" -- confirmStartupの値が“false”なのでシステム環境設定を終了
else -- confirmStartupの値が“false”で無い場合
if curPaneID is not {} then -- curPaneIDが存在する場合
tell application "System Preferences"
set current pane to pane id curPaneID -- スクリプト実行開始時に表示していたペインに切り替え
end tell
else -- curPaneIDが存在しない場合
activate application "System Preferences"
tell application "System Events"
tell process "システム環境設定"
click menu item "すべての環境設定を表示" of menu 1 of menu bar item "表示" of menu bar 1
-- すべての環境設定を表示する
end tell
end tell
end if
end if


-- 現在のペインのIDを取得
on getCurPaneID()
set curPaneID to {}
tell application "System Preferences"
if exists current pane then
set curPaneID to get id of current pane
end if
end tell
return curPaneID
end getCurPaneID


-- メニューアイテムをクリック
on clickMenuItem(menuItem, buttonNum)
try
tell application "System Events"
tell process "システム環境設定"
tell window "Mission Control"
tell group 1 of sheet 1
tell pop up button buttonNum
click
delay 0.1
click menu item menuItem of menu 1
delay 0.2
end tell
end tell
end tell
end tell
end tell
return true
on error
return false
end try
end clickMenuItem

macOS Big Sur 11.1、iMac (Retina 5K, 27-inch, 2019)で動作を確認してます。

更新履歴

inserted by FC2 system