Skip to content

Instantly share code, notes, and snippets.

@davedelong
Last active September 10, 2022 04:40
Show Gist options
  • Save davedelong/850409c512ab2d2a21aa6fa690096d56 to your computer and use it in GitHub Desktop.
Save davedelong/850409c512ab2d2a21aa6fa690096d56 to your computer and use it in GitHub Desktop.
Toggle Dark Mode
on setDarkMode(shouldBeDark)
set paneID to "com.apple.preference.general"
tell application "System Events"
if dark mode of appearance preferences is shouldBeDark then return
end tell
set paneWasOpen to false
(*
If SysPrefs is already running and showing the "General" pane,
then toggling dark mode causes the UI of the pane to become
out-of-sync with actual system appearance. To account for this,
we'll quit SysPrefs if it's open to General prefs, and then
re-open it after we've made the change
*)
if application "System Preferences" is running then
tell application "System Preferences"
if show all is false and id of current pane is paneID then
set paneWasOpen to true
quit
end if
end tell
end if
tell application "System Events"
set dark mode of appearance preferences to shouldBeDark
end tell
if paneWasOpen then
tell application "System Preferences"
launch
delay 3
activate
reveal (the first pane whose id is paneID)
end tell
end if
end setDarkMode
set result to display dialog "Set System Appearance" buttons ["Light Mode", "Dark Mode"]
if button returned of result is "Light Mode" then
setDarkMode(false)
else
setDarkMode(true)
end if
@Write
Copy link

Write commented Apr 6, 2022

bigsur already do this by itself, this script is only needed before bigsur version

yeah ? well Monterey didn't fixed it for me, the auto-toggle is always pure shitshow.

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