Skip to content

Instantly share code, notes, and snippets.

Last active Oct 18, 2018
What would you like to do?
Toggle Mojave's dark mode automatically based on given time.
# • 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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
-- 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
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