Skip to content

Instantly share code, notes, and snippets.

@skempken
Last active November 7, 2022 15:27
Embed
What would you like to do?
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