Last active
September 10, 2022 04:40
-
-
Save davedelong/850409c512ab2d2a21aa6fa690096d56 to your computer and use it in GitHub Desktop.
Toggle Dark Mode
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yeah ? well Monterey didn't fixed it for me, the auto-toggle is always pure shitshow.