Apple - Turn on dark mode at a certain time
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)- If you want to make it run for all users, put it in
/Library/LaunchAgents
(Macintosh HD). - This
.plist
is just a text file that you can edit in any text editor and save as text with the extensions.plist
. - You likely have existing files in those folders that you can duplicate to create your own. If you open an existing
.plist
file withTextEdit.app
, you won't accidentally save it as a.rtf
file or something.
- If you want to make it run for all users, put it in
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>
- The line below
<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. - The array below
<key>StartCalendarInterval</key>
that saysHour
andMinute
is where you set the time. Current set time isH 21 M 20
= 9:20pm
These 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.
- Run Script Editor application
/Applications/Utilities/Script Editor.app
.- Paste in whichever Applescript you wish to use (At the top of the answer in case you forgot)
- You can test run the Applescripts in this application by pressing the play button.
- Save as
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
. - Return to your
.plist
file from step 2, and change the line below<string>osascript</string>
to point at your new Applescript (.scpt
file).
- When both files are created, an important step is to log out (or restart) because these launch agents start running in the background on launch.
- If you want to stop it from running, you can move the
.plist
from the folder or just delete it.
- If you want to stop it from running, you can move the
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