Automating Dark Mode
Back in the monochrome days of PC computing, our choices were green on black, or amber on black. The amber monitors actually cost a bit more because European studies of the day showed amber was easier on the eyes.
Apple's Macintosh Computer introduced the black text on white paper look. In emulating paper though, I found my eyes fatiguing more quickly. I expressed to a friend and colleague that it felt like a swath of electrons beaming into my eyes, in which he replied, "okay."
To this day, I'm not sure if he was in solid agreement, or patting my head and humoring me. Judge for yourself with the sample color schemes I've created at the end of this post.
With macOS Mojave, Apple introduced Dark Mode, which in essence, is a return to the calm and focused energy levels of green, amber, and black. I really like it, but one cannot live on dark chocolate and dark coffee alone. We can switch between Dark Mode and Light Mode via the System Preferences.
But wouldn't this all be more delicious if we can change modes, automatically, depending on the time of day? What follows is a way to accomplish that, but not in a push button app friendly way. It's more of a DIY project which requires elementary Apple Developer skills:
- Download the dark-mode source code from github
- Build with Xcode 10.0
- Install in /usr/local/bin
- Create two launch agents in ~/Library/LaunchAgents
$ dark-mode --help
Usage
$ dark-mode [command]
Commands
[none] Toggle dark mode
on Enable dark mode
off Disable dark mode
status Dark mode status
Created by Sindre Sorhus
Thank you Sindre.
To get dark-mode to run at specific times, the Linux developer in me reflexively went to cron, but that would have been a mistake. Apple still supports cron, but favors launchd. Thus, instead of using crontab, I created two property list (plist) files to turn dark-mode on and off. Because I want dark-mode to run only for me, that is, be user specific, the plist files live in my home directory, under Library/LaunchAgents.
The two files are named com.myam.dark-mode-on.plist and com.myam.dark-mode-off.plist, but remember to rename the file to use your own userid (instead of myam). It's not required, but gets you points for neatness and consistency. Note Apple's keywords to mark time intervals.
com.myam.dark-mode-off.plist
<?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>com.myam.dark-mode-off</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/dark-mode</string>
<string>off</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>9</integer>
<key>Minute</key>
<integer>30</integer>
</dict>
</dict>
</plist>
________________________________________
<?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>com.myam.dark-mode-on</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/dark-mode</string>
<string>on</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>19</integer>
<key>Minute</key>
<integer>30</integer>
</dict>
</dict>
</plist>
________________________________________
Comments