Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.


macrumors 68040
Original poster
Oct 3, 2009
I think it makes a lot of sense to use Dark Mode at night, and to use Light Mode during the day. Dark is easier on the eyes at night, and light is easier to see during the day. Strangely, while Apple has a way of scheduling Night Shift, they did not think of this for Dark Mode.

I like to avoid having to install 3rd party apps for little things like this, so I figured out a way to do it with AppleScript and Calendar. Here's how.

1. Open AppleScript Editor and paste this in:

tell application "System Events"
    tell appearance preferences
        set dark mode to not dark mode
    end tell
end tell

2. Go to File > Export, and change the File Format to Application. Name it "Toggle Dark Mode" and save it somewhere. This app, when run, will toggle between Dark and Light modes. You can even use this app to manually switch modes if you want.

3. Open Calendar.

4. Now we will prepare Calendar for running an app as a timed alert. This is a feature of Calendar, but for some reason it doesn't work for iCloud calendars, so we have to enable the good old "On My Mac" calendar for this. This won't interfere with your other iCloud calendars.

To do that, here's a little trick I found: Show the left Calendars pane, then select a calendar name that isn't and iCloud calendar - such as the "Birthdays" calendar.

Then right click the blank white space underneath it, and choose "New Calendar". This should create a new On My Mac calendar at the top of the list.

Screenshot 2018-09-28 at 16.03.16.png

5. You should have a new "On My Mac" category appear, with a new calendar within it. Name it whatever you like, I called it "Scripting" as I will be using it to run scripts such as this one.

Screenshot 2018-09-28 at 16.03.34.png

6. Create a new event for today, call it "Dark Mode On".

7. Create a Custom alert. For alert type, choose "Open File".

Point it to the "Toggle Dark" file you created in Step 2.

Make it run "At the time of event".

Set the time of the event to when it starts to get dark.

Screenshot 2018-09-28 at 16.09.28.png Screenshot 2018-09-28 at 16.11.10.png

8. Set this event to repeat daily.

9. Duplicate the event and name it "Dark Mode Off". Change its start time to when the sun rises.

10. In the left Calendar pane, uncheck the "Scripting" calendar so it doesn't clutter up your calendar. It will still work the same.

That's it. Test it out, it should work! It even runs when your Mac is sleeping (or at least it runs as soon as it wakes up).

One minor annoyance with it is that the transition from dark to light is abrupt, not smooth like when you change the appearance in System Preferences. I don't know if there's a way to make the AppleScript do that. Any ideas? But 3rd party apps don't do the transition either, so at least it's not any worse.

Another annoyance is that each time the event runs, you get a notification banner. I don't know how to have the Calendar event just run the app without there also being a notification alert. If you have any ideas, let me know!

Let me know if it works or if it doesn't, and if you have any improvements, such as disabling the notification banner and making it switch smoothly between dark and light modes!

Update: It seems that it doesn't always work while my mac is sleeping. It worked twice, but on the third try, it didn't.
Last edited:
  • Like
Reactions: neliason


macrumors newbie
Sep 21, 2012
Instead of using Calendar, maybe use crontab and a shell script that determines if it is time to toggle between dark or light mode. It could check every 5 or 10 min throughout the day.

A null ~/.darkmode file could be touched when in dark mode and removed when in light mode. Then the script would know if it is already been toggled on or off.

Use osascript command to run the /path/to/Toggle\ Dark\ Mode.scpt file from within the shell script.

To get the current time into a variable do something like TIME=`date "+%H:%M"`; will return the current hour and minute, example 15:45.
Last edited:
  • Like
Reactions: baryon


macrumors newbie
Sep 21, 2012
When using launchctl, it only asks to gain access to control system when the start / stop times are changed in the bash shell script.

Currently it is checking every 10 min to see if Dark or Light mode is toggled properly during their assigned time frame.

If it is manually overridden through the general preference pane, then it wont try to change again until the next light/dark cycle starts.

I'll try to upload the script and .plist tonight if it doesn't blow up on me before then. :)
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.