Toggle Dark Mode with Touch Bar
(Source/Credits: https://dev.to/oihamza/toggle-dark-mode-with-touch-bar-3o8n)
Create a Touch Bar shortcut that toggles between dark mode and light mode.
title: Toggle Dark Mode with Touch Bar published: true description: Create a Touch Bar shortcut that toggles between dark mode and light mode. tags: touch-bar, shortcut, dark-mode cover_image: https://thepracticaldev.s3.amazonaws.com/i/8jkbs2bgnkbf979zs9xu.jpg
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.
🌞🌚
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"
Step 2)
Implementing the script
Change the workflow selection to "no input"
Change the image to your desired icon. This will appear on the Touch Bar. I selected the color wheel.
In the Actions search bar type "Run AppleScript"
Double click "Run AppleScript" and you’ll see this 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:
Let's test out the script by clicking the "Run" button
Switch back to the light mode by clicking "Run" again.
Let's go ahead and save the script. I named mine “Dark Mode Toggle”
Step 3)
Creating the Touch Bar shortcut. We’re almost there!
On System Preferences → Extensions, make sure the Dark Mode Toggle is checked
Click on 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.
Congratulations, you did it! 😎
Connect with me on Twitter @oiHamza. 👨🏽🚀
Comments section