Last active
May 11, 2023 00:48
-
-
Save skempken/46c184c1a5eac2e88c9c31ce09a38300 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use AppleScript version "2.4" -- Yosemite (10.10) or later | |
use framework "Foundation" | |
use framework "AppKit" | |
use scripting additions | |
tell application "System Settings" | |
activate | |
current application's NSWorkspace's sharedWorkspace()'s openURL:(current application's NSURL's URLWithString:"x-apple.systempreferences:com.apple.Displays-Settings.extension") | |
delay 0.5 | |
tell application "System Events" | |
tell process "System Settings" | |
key code 48 | |
key code 48 | |
key code 48 | |
key code 123 | |
delay 0.5 | |
-- activate hdr on left monitor | |
set hdr to checkbox 1 of group 3 of scroll area 2 of group 1 of group 2 of splitter group 1 of group 1 of window "Displays" of application process "System Settings" of application "System Events" | |
tell hdr | |
if value is 0 then click it | |
end tell | |
-- switch to right monitor by key navigation. Actions like "click" are not invocable on the buttons. | |
-- hit "tab" (key code 48) three times, it's the only way to be sure ;-) | |
-- hit "right" to select the right monitor | |
key code 124 | |
delay 0.5 | |
-- do it again | |
set hdr to checkbox 1 of group 3 of scroll area 2 of group 1 of group 2 of splitter group 1 of group 1 of window "Displays" of application process "System Settings" of application "System Events" | |
tell hdr | |
if value is 0 then click it | |
end tell | |
end tell | |
end tell | |
quit | |
end tell | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See this PR alin23/mac-utils#5