Last active
October 18, 2018 02:06
-
-
Save pakLebah/2bcb67b0e8c342e394df604c37a0850e to your computer and use it in GitHub Desktop.
Toggle Mojave's dark mode automatically based on given time.
This file contains hidden or 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
# NOTES: | |
# • Don't forget to change every <HOME> in the scripts to your home folder name. | |
# • Copy .plist and .scpt files into your Library/LaunchAgents folder. | |
# • First time execution would require permission. | |
# • Toggle time is hard coded in the script as: | |
# – light mode: 07:00-17:00 (day time) | |
# – dark mode: 17:00-07:00 (night time) | |
# • Execution interval: every 10 minutes (600 seconds). | |
# load task | |
$ launchctl load -w /Users/<HOME>/Library/LaunchAgents/local.darkmode.toggle.plist | |
# unload task | |
$ launchctl unload /Users/<HOME>/Library/LaunchAgents/local.darkmode.toggle.plist | |
# check task | |
$ launchctl list | grep local |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>local.darkmode.toggle</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/bin/osascript</string> | |
<string>/Users/<HOME>/Library/LaunchAgents/local.darkmode.toggle.scpt</string> | |
</array> | |
<key>StartInterval</key> | |
<integer>600</integer> | |
<key>RunAtLoad</key> | |
<true/> | |
</dict> | |
</plist> |
This file contains hidden or 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
-- get seconds since midnight | |
set ticks to (time of (current date)) | |
tell application "System Events" | |
tell appearance preferences | |
set dark to dark mode | |
-- time > 17:00 or time < 07:00 | |
if ticks ≥ 61200 or ticks ≤ 25200 then | |
if not dark then | |
set dark mode to true | |
set appearance to graphite | |
set highlight color to graphite | |
end if | |
else | |
if dark then | |
set dark mode to false | |
set appearance to blue | |
set highlight color to blue | |
end if | |
end if | |
end tell | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment