Automating Dark Mode

How to automate 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.

System Preferences dialog box for dark mode
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:

  1. Download the dark-mode source code from github
  2. Build with Xcode 10.0
  3. Install in /usr/local/bin
  4. Create two launch agents in ~/Library/LaunchAgents
Using dark-mode from Terminal is straightforward:

$ 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 launchdThus, 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>
________________________________________

com.myam.dark-mode-on.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>


I have configured dark-mode to turn off at 9:30 am and turn on at 7:30 pm. Customize to suit your needs.  It would be even cooler to have dark-mode turn on and off automatically during sunset and sunrise, but that's another project.
________________________________________

Monochrome Green sample is akin to Dark Mode
Monochrome Green

Eurospec Amber sample is akin to Dark Mode
Eurospec Amber
Paper White sample used to compare to green and amber.
Paper White



Comments

Popular posts from this blog

Bookshelf Classic: The Design and Evolution of C++

Bitcoin: 15 minutes (or more) of privacy

XO: SO-SO future