Skip to content

Instantly share code, notes, and snippets.

@skempken
Last active May 11, 2023 00:48
Show Gist options
  • Save skempken/46c184c1a5eac2e88c9c31ce09a38300 to your computer and use it in GitHub Desktop.
Save skempken/46c184c1a5eac2e88c9c31ce09a38300 to your computer and use it in GitHub Desktop.
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
@anarchy89
Copy link

@skempken it works perfectly, do you mind sharing the code so that I can just save my UUID into the program and compile it?

@alin23
Copy link

alin23 commented Mar 20, 2023

@alin23 your program does a toggle, i was wondering if it was possible to a force on, so if it was on, it would be left alone, but if it was off, it would be turned on.. is that possible?

Yes, I just added that a few minutes ago. You can download the updated binary.

Hi, sorry, the ToggleHDR binary still does a toggle action. Not force on.

Most likely you haven't updated the binary. See below how it works:

Running without arguments (shows help)

> ToggleHDR

ID  UUID                                    Supports HDR    HDR Enabled     Name
1   37D8832A-2D66-02CA-B9F7-8F30A301B230    false           false           Built-in Liquid Retina XDR Display
2   3B300CA4-8F5F-4E77-A757-CFD72454C30A    true            false           LG Ultrafine

Usage: ToggleHDR [id/uuid/name/all] [on/off]

Running with the on argument (enables HDR for all displays)

> ToggleHDR on

ID  UUID                                    Supports HDR    HDR Enabled     Name
1   37D8832A-2D66-02CA-B9F7-8F30A301B230    false           false           Built-in Liquid Retina XDR Display
2   3B300CA4-8F5F-4E77-A757-CFD72454C30A    true            true            LG Ultrafine

Enabling HDR for LG Ultrafine [ID: 2]

@skempken
Copy link
Author

@skempken it works perfectly, do you mind sharing the code so that I can just save my UUID into the program and compile it?

See this PR alin23/mac-utils#5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment