After upgrading to macOS Mojave, I was wondering if there is a setting which would automatically turn on Dark Mode at a certain time of day?
I only found the setting to turn it on and off manually.
After upgrading to macOS Mojave, I was wondering if there is a setting which would automatically turn on Dark Mode at a certain time of day?
I only found the setting to turn it on and off manually.
In case someone is interested in an answer that doesn't require you to install anything but does require you to touch code just a little... Here you go....
How to toggle dark mode with Applescript:
tell application "System Events"
tell appearance preferences
set dark mode to not dark mode
end tell
end tell
How to turn ON dark mode with Applescript:
tell application "System Events"
tell appearance preferences
set dark mode to true
end tell
end tell
How to turn OFF dark mode with Applescript:
tell application "System Events"
tell appearance preferences
set dark mode to false
end tell
end tell
There are pretty robust applications out there that can run scripts or actions at a specific time, but these applications are mostly fairly extensive and expensive. I did want to mention one because it allows you to do more than just toggle the dark mode: Keyboard Maestro - It's sort of like Automator, but better. Don't let the outdated look fool you.
I would use launchd, because it doesn't require you to install anything. It does require you to touch a little bit of code, but nothing major.
How to trigger Applescript at a specific time with Launchd property list file (plist):
You need to make a new .plist
file in ~/Library/LaunchAgents
(~ represents your user folder)
/Library/LaunchAgents
(Macintosh HD). .plist
is just a text file that you can edit in any text editor and save as text with the extensions .plist
. .plist
file with TextEdit.app
, you won't accidentally save it as a .rtf
file or something.Copy & paste this in the .plist
file:
<?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.time.trigger.darkmode</string>
<key>Program</key>
<string>/usr/bin/osascript</string>
<key>ProgramArguments</key>
<array>
<string>osascript</string>
<string>/Users/joonaspaakko/Desktop/toggle-darkmode.scpt</string>
</array>
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Hour</key>
<integer>21</integer>
<key>Minute</key>
<integer>20</integer>
</dict>
</array>
</dict>
</plist>
<string>osascript</string>
points to the Applescript .scpt
file that should be triggered. You will change this in step 3 after creating a script file.<key>StartCalendarInterval</key>
that says Hour
and Minute
is where you set the time. Current set time is H 21 M 20
= 9:20pmThese steps are maybe a little backwards since I already have the script location set in the .plist
but let's create the .scpt
file next.
/Applications/Utilities/Script Editor.app
.
Script
file. If you're just using the script yourself, save it somewhere under your home directory. If you're setting this up for all accounts you'll need to store it in a location everyone can access, such as /Library/Scripts
..plist
file from step 2, and change the line below <string>osascript</string>
to point at your new Applescript (.scpt
file)..plist
from the folder or just delete it.f.lux can switch between Mojave's light/dark modes at sunrise/sunset ("Color Effects"):
OS X Dark theme at sunset: Uses the normal theme during the day and switches to dark theme (dock and menu bar) each night at sunset. Disabling f.lux will also disable dark theme.
There is no native OS way at the moment, but you can use some software like
» NightOwl
or write your own script in the Apple Script Editor to do it by click
tell application "System Events"
tell appearance preferences
set dark mode to not dark mode
end tell
end tell
Another option is a launchd plist I created for myself and shared on Github.
My profile is set to 9pm and 7:15am, you can change this easily. I have included a single terminal command to install it. It does not install any software, uses only standard macOS tools. In fact I have pretty much done the same as what Joonas suggested you do in his answer, and shared it so you don't have to type it out.
As @Gert-JanRoeleveld mentioned, @Joonas largely has the right approach. However there are a few missing details to be clarified/improved upon:
launchd
script to automatically kick in whenever you log in, it needs to be placed in ~/Library/LaunchAgents
or /Library/LaunchAgents
, and the filename should match the "Label" key, i.e., com.time.trigger.darkmode.plist
. It needs to be a plain text file. It won't start until you next log in unless you launchctl load ~/LaunchAgents/com.time.trigger.darkmode.plist
for example./Users/joonaspaakko/Desktop/toggle-darkmode.scpt
. Other users will not have access to this file, and thus the script will not work for anyone else (this is generally considered bad practice).Instead, include the AppleScript within the plist itself:
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.time.trigger.darkmode</string>
<key>Program</key>
<string>/usr/bin/osascript</string>
<key>ProgramArguments</key>
<array>
<string>osascript</string>
<string>-e</string>
<string>tell app "System Events" to tell appearance preferences to set dark mode to not dark mode</string>
</array>
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Hour</key>
<integer>21</integer>
<key>Minute</key>
<integer>20</integer>
</dict>
</array>
</dict>
</plist>
dark mode
with a negated boolean within the command) really needs to go to Brett Terpstra.Another 3rd party option is LightsOff.
It also enables controlling which apps switch themes, and can also switch them for some other 3rd party apps with light/dark themes, though not all.