As a hobby developer, when testing dark theme vs light theme under MacOS X, I have those moments where I have to switch back and forth between both themes quite often.
Going into the System Preferences to toggle theme, choosing the Appearance option, and then selecting the desired theme, does indeed work, but I wanted just a “one click” theme toggle.
To help myself with that, I created a small application that does exactly this: it toggles to “the other” theme, with just a simple click.
So when Dark Theme is active, it switches to the Light (Aqua) Theme. If however the Light Theme is active, it switches to Dark Theme.
The application is super simple, and has no interface. Just start the App and it changes theme and then closes itself.
Normally, this App would just sit in your Applications directory, with the optional shortcut in your Dock or even on the Touch Bar (if your Mac has one).
Quickly Toggle Theme
I think the above explanation pretty much says it all …
This application, called “ToggleTheme“, toggles between Dark and Light (Aqua) theme with just a single click to open the application – nothing more, nothing less.
When started, you will see nothing except that the theme on your Mac will change.
So in essence you could place it in your Dock, Touch Bar, or even use a keyboard shortcut, as if it were a button.
Using Apple Script
This application, in its core, uses a simple Apple Script, executed by “osascript“.
This is the “core” script I’m using, so if you’d like you can use that instead (in Automator or from Terminal). It sounds ridiculous, I know … until a buddy of mine asked for how I did this and if I could put it in a small application … (done with Lazarus Pascal)
1 2 3 4 5
| tell application "System Events"
tell appearance preferences
set dark mode to not dark mode
end tell
end tell |
Compatibility
So far I have tested ToggleTheme and used this application under MacOS 10.14 (Mojave), and 10.15 beta (Catalina).
ToggleTheme is a 64 bit application and both DMG and Application have been signed.
Since Dark Theme support is rather limited in MacOS versions prior to 10.14, your mileage may vary. It may work, or it may not work.
Ad Blocking Detected Please consider disabling your ad blocker for our website.
We rely on these ads to be able to run our website.
You can of course support us in other ways (see Support Us on the left).
Installing the ToggleTheme application
Obviously installation is equally simple:
- Download and Open the ToggleTheme DMG
- Drag ToggleTheme to your Application directory
And that’s all.
Download ToggleTheme
Uninstall ToggleTheme
Uninstalling ToggleTheme is very easy as well, simply drag the ToggleTheme application to your Trashcan.
ToggleTheme does not create or use any additional files.
Quick Access
Here a few options to get quick access to toggle dark/light themes: Dock, Keyboard Shortcut and Touch Bar.
They are not mutually exclusive, so you can more than one if you’d like.
Place ToggleTheme in the Dock
This is how I use it … probably the easiest thing to do and the application will be easy to find.
After installation, simply drag the ToggleTheme icon from your Applications directory to the dock, just like you’d do with other applications.
Tip: For those having a Touch Bar on their Mac, consider using “Pock” which places your Dock in Touch Bar. It works pretty slick and it’s free!
ToggleTheme Shortcut in your MacOS Dock
Create a Quick Action (Automator) for other Shortcuts to ToggleTheme
There are 2 more shortcuts you could create: a Keyboard Shortcut or a Touch Bar shortcut.
For either of them you’ll need a quick to create a so called Quick Action (also known as “Service”) with “Automator” which can be found in the Applications directory.
You can use the same Quick Action in case you decide to use both Keyboard and Touch Bar shortcut – even at the same time.
Tip: If you are considering a Touch Bar shortcut, consider using “Pock” instead, which places your Dock in Touch Bar. It works slick and it’s free!
Now to make things more confusing; with the Automator we can go 2 routes, depending on your preferences.
- The first option would be to use the AppleScript I have shown earlier. For the paranoid, this would be ideal since you have full insight in the code.
- The second option would be to have Automator run the ToggleTheme application. Personally, I prefer this method, but to each their own.
I’ll explain both here, as they work very similar.
The key is that we can see ToggleTheme as a service, so we can tie it to a keyboard or touch bar shortcut.
Step 1: Create a Quick Action with Automator
Open “Automator” (found in “Applications“). A dialog will open where we will select “New Document“.
Again a new window will open, where we will select “Quick Action” (may also be called “Service”) followed by clicking the “Choose” button;
ToggleTheme – Open Automator for a new Quick Action
In the newly opened window, you’ll see “Workflow receives” in the top center of the window.
Set this field to “no input“;
ToggleTheme – Automator “No Input”
Now the step (step 2) depends on the approach you’d like to use.
Step 2A: If you want to use the application ToggleTheme
Follow this step if you are going to use the Application, and skip step 2B.
Here we only need to add the “Action” called “Launch Application”.
For this to work, ToggleTheme needs to be installed in your “Applications” directory otherwise it most likely will not be listed.
Follow these steps:
Click “Actions” on the far left, and look for “Launch Application” in the second column and drag “Launch Application” to the third column (as shown below).
In the newly added “Launch Application” box, select the application “ToggleTheme” from the dropdown box:
ToggleTheme – Automator “Launch Application”
You can click the “Run” ( ) button to test the script – your theme should change after clicking this button.
Step 2B: If you want to use the AppleScript instead
Follow this step if you’re going to use the AppleScript and skip step 2A.
Here we only need to add the “Action” called “Run AppleScript”.
Follow these steps:
Click “Actions” on the far left, and look for “Run AppleScript” in the second column and drag “Run AppleScript” to the third column (as shown below).
In the newly added “Run AppleScript” box, we will now have to enter the AppleScript code as show below;
Replace the text in the box with:
1 2 3 4 5
| tell application "System Events"
tell appearance preferences
set dark mode to not dark mode
end tell
end tell |
So it should look like this:
ToggleTheme – Automator “Run AppleScript”
You can click the “Run” ( ) button to test the script – your theme should change after clicking this button.
If this doesn’t happen: verify the code you’ve just pasted in there and try again.
Step 3: Save the Automator Quick Action
From the “File” menu choose the option “Save“.
In the dialog that opens, you can give your Quick Action a name, for example “ToggleTheme“, and click “Save“. You can close “Automator” now.
ToggleTheme – Automator – Save Quick Action
Creating the Keyboard Shortcut for ToggleTheme (Quick Action)
After you have created the Quick Action, you can now create a Keyboard Shortcut;
Open the Apple menu ( ) and select “System Preferences“, click on “Keyboard“, and finally go to the “Shortcuts” tab.
Next click “Services” and scroll all the way to the bottom where you’ll find your new Automator Quick Action.
I called it “ToggleTheme“, but you may have chosen a different name.
Select your Quick Action, and you’ll see a “Add Shortcut” button appear, which you should click.
Now you can press a key combination which you’d like to use to toggle your theme.
I’ve tried this with SHIFT+CTRL+COMMAND+T.
Right away after pressing this key combination you’ll see the key combination in the “ToggleTheme” line.
To test this you can press the key combination again, and your theme should change.
However … If you picked an already existing key combination, your theme may not switching.
You’ll either have to pick a different key combination, or disable or change the predefined key combination of that other function first.
Create a Shortcut on your Touch Bar
For those who have a MacBook with a Touch Bar – no matter how many people complain about it; I just love it, even though it could use some fine tuning (eg. add applications to the touch bar layout). Again consider using “Pock” instead, since Apple’s implementation requires pressing a button twice to execute the script. A tool called BetterTouchTool allows for way more customization, however it’s not free and fairly complex.
Anyhoo … first you’ll need to create the Quick Action we just described so it will be available.
To create the Touch Bar shortcut (a little sketchy if you ask me);
Open the Apple menu ( ) and select “System Preferences“, click on “Extension” (at the end of the 3rd row, looks like a puzzle piece) and scroll to the bottom where you select “Touch Bar“. The Quick Action should be visible here!
Here we click “Customize Control Strip“. Your screen will fade and some Touch Bar icons will be shown that can be dragged to the bottom of your screen where they than appear on your Touchbar. The icon you’re looking for is called “Quick Assists” (it could also be called ‘Workflows”) – drag it on your Touch Bar and you’re done.
Customize your Touch Bar
Now comes the annoying part: to use the shortcut on your Touch Bar you’ll first have to press the “Quick Actions” icon and after that the “ToggleTheme” button.
Not as convenient as I had hoped for.
Touch Bar – You’ll have to tap 2 buttons
Now to show off what Pock can do: I’ve added ToggleTheme to my Dock and am running Pock on my MacBook Pro.
I just have to tap the Toggle Theme icon and I’m good to go. No Quick Action needed …
This is what Pock can do for your Touch Bar
In case you’re wondering how I have made screenshots from the Touch Bar: This can be done with SHIFT+COMMAND+6 … something I had to figure out as well.
Comments
There are 2 comments. You can read them below.
You can post your own comments by using the form below, or reply to existing comments by using the "Reply" button.
Believe it or not, this is just what I was looking for.
I’m working with Lazarus as well and the current state of Cocoa makes me want to test different themes over and over again to make sure nothing goes wrong.
Thanks man!
John
Awesome – Thanks John!
Feel free to contact me – would be cool to exchange Lazarus related knowledge!
hans