DEV Community

loading...
Cover image for Toggle Dark Mode with Touch Bar

Toggle Dark Mode with Touch Bar

oihamza profile image Hamza ・3 min read

If you’re anything like me, you enjoy changing between dark mode and light mode based on what vibe you’re feeling.

Here’s a quick and to-the-point tutorial where I'll show you how to add a shortcut to your MacBook's Touch Bar that makes switching all that much easier.

🌞🌚

cat saying are you ready

What we'll be doing

Very simply, we’ll be creating an Automator script that allows us to create a shortcut for dark/light mode. Once we have the script set up, we will add a Touch Bar shortcut to make switching between the two modes easier.

If you're not familiar with any of these things, don't worry as I've listed each step with helpful screenshots to guide you. We've got this!

What you’ll need:

  • MacBook w/Touch Bar 👆🏽💻
  • macOS Mojave

Step 1)

Create the script that automates the light → dark mode process

→ Open Automater
→ Create a New document
→ Create a quick action, and then click "Choose"

Create a new document and then quick action

Step 2)

Implementing the script

Change the workflow selection to "no input"

change to no input

Change the image to your desired icon. This will appear on the Touch Bar. I selected the color wheel.

change the image

In the Actions search bar type "Run AppleScript"

Alt Text

Double click "Run AppleScript" and you’ll see this page

Run AppleScript page

Delete the existing code, and replace it with the following code:

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

It should look like this:

Updated code

Let's test out the script by clicking the "Run" button

Test the script

Switch back to the ​light mode by clicking "Run" again.

Let's go ahead and save the script. I named mine “Dark Mode Toggle”

Save your script

Step 3)

Creating the Touch Bar shortcut. We’re almost there!

On System PreferencesExtensions, make sure the Dark Mode Toggle is checked

system preferences → extensions

Click on Customize Control Strip

customize control strip

This will take you to this page, where you can drag your quick action to your desired location on the keyboard. I chose to put mine on the far right.

Note: you'll have to drag it towards the desired place on your Touch Bar. See more here.

Touch Bar icons

Drag the icon to your desired Touch Bar location

Congratulations, you did it! 😎

Connect with me on Twitter @oiHamza. 👨🏽‍🚀

Discussion (0)

pic
Editor guide