DEV Community

Cover image for Toggle Dark Mode with Touch Bar
Hamza
Hamza

Posted on

Toggle Dark Mode with Touch Bar

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 Preferences โ†’ Extensions, 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. ๐Ÿ‘จ๐Ÿฝโ€๐Ÿš€

Top comments (0)