macOS keyboard shortcut to toggle Dark Mode

Geert Cuppens
2 min readJul 18, 2019

--

This guide describes the steps to follow to toggle Dark Mode in macOS via a keyboard shortcut sequence, as shown in the video below.

TL/DR;

If you already know your way around macOS and it’s scripting and automating functionality, here are the steps you’ll need.

Keep reading for the full explanation of all steps!

  • Save the Applecript code to toggle Dark Mode as an app
  • Create a new Automator Workflow for that new app
  • Configure a keyboard shortcut sequence in System Preferences

Applescript Code

I’m using the following AppleScript code to toggle Dark Mode, I believe it’s the most optimised and clean code:

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

Follow these steps:

  1. Open Script Editor on your macOS
  2. Choose ‘New Document’ in the bottom left corner
  3. Copy the code above and then paste it into the editor
  4. Press the ‘play’ icon in the Script Editor’s Toolbar
  5. You’ll see the code being formatted and executing once already (just to show it works)
  6. Choose ‘file’ and then ‘save’
  7. Choose a name for your script, e.g. ToggleDarkMode.app
  8. Choose ‘Application’ as File Format and leave all other options as they are
  9. Done!

You now have an application called “ToggleDarkMode” in your launchpad.

Automator Workflow

Let’s now create an automator workflow to be able to attach a keyboard sequence to launch the new app.

  1. Launch Automator on your macOS
  2. Choose ‘new document’ in the bottom left corner
  3. Choose ‘Quick Action’ in type of document window
  4. Set the “Workflow receives” to “no input”
  5. Search or browse for the “Launch Application” action and double click it to add it to the workflow
  6. In the drop-down list, select your new app “ToggleDarkMode.app”
  7. Choose ‘file’ and then ‘save’ and give your Quick Action a name, e.g. Toggle Dark Mode
  8. Done!

Configure Keyboard Shortcut

Now we are able to configure a keyboard shortcut to your Quick Action which will then launch the ToggleDarkMode app. To do this, do this:

  1. Open ‘System Preferences’, then ‘Keyboard’ and choose the ‘shortcuts’ tab
  2. Select ‘services’ in the left list and then browse down to ‘General’
  3. Select your “Toggle Dark Mode” and choose “add shortcut”
  4. I’m using control+option+command+U
  5. done!

MacOS will ask for your permission the first time you’re running the app via the keyboard shortcut, you can simply allow it by pressing “ok”.

There, that’s all, you can now toggle Dark Mode by pressing the keyboard sequence you have chosen, enjoy!

--

--

Geert Cuppens
Geert Cuppens

Responses (6)