Image for post
Image for post

Switch Dark Mode on Mac OS Mojave as simple as one clic ? I built an App for it !

Dark Mode is a feature that you might have already probably noticed if you are already MacOS Mojave beta testers. This feature has been asked from Apple for years.

I have been on the beta since the first beta release, so I would say more than 3 weeks now and even if I am a night kind of person I like to switch between light and dark mode depending of the time of the day or just because I want to play with it.

Image for post
Image for post
General panel to change the appearance mode

In order to do so, you need to go to your Preference Panel then General then you can finally switch mode… OK, the first time is fine it is funny… but will you often change if it takes you 2 seconds each time ?

First of all steps are a bit too much for this kind of settings. It’s not a screen saver image that you need/ want change once a month (yeah some do more oftenly..).

I definitely see someone changing this settings twice or more a day !.

Something paradoxal is that Mac OS is full of shortcuts to increase productivity, this is one of the reason we like it right ?!. So why any of them exist for this ? Maybe Apple will think about it and will create it on the near future something for it, but I don’t think it will happen soon. Just imagine if in order to activate the bluetooth mode you need to go to your preference panel every time !.

So I decided to create a small status bar application that give you a short way to change settings. This App is an Open Source App named Darky.

This App allow you to switch manually from Dark to Light mode with a simple switch or just by using a shortcut (Cmd + Cntrl + B).

Image for post
Image for post

You can find the source code repository . If you prefer to download directly the App and install it, the version 0.1.0 is ready to download

Screen Capture of Darky

Image for post
Image for post
Image for post
Image for post
Dark Mode On and Off

Technical Bits

Now I will sound a bit more technical, and will explain how Darky works and why also it is not on the Mac OS App Store !

First of all as you are already aware, Apple has very strict guidelines when it is about controlling preference settings. Especially since every Mac App is now sandboxed and can access only to their own files. If any requirement for accessing outside the sandbox is necessary, a request to Apple need to be made and approved.

All of this is done by adding exceptions or scripting-targets if you need to open Mail App for example. Exceptions are used to access ressources outside your App. You really need to be persuasive to let Apple allowed you some exceptions.

Indeed, in my case exception I was looking for was the complete control of Preferences Panel but there is not scripting-targets api available for Dark Mode.. yet.

Those exceptions are never allowed by Apple as it could be too risky for the user.

I kind of agree however it should be approved case by case for legitimate App. So the only was to send event to the panel is via a powerful and not very common Apple Script command !

To make this working, first of all we need to add some temporary exceptions for Apple Events which will allow Apple Script file to be executed outside the App sandbox and System Preference in order to be able to change settings inside it

Entitlement file content

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ""><plist version="1.0"><dict><key></key><true/><key></key><array><string></string><string></string></array></dict></plist>

Apple Scripts

This Apple Script below get the value of the DarkMode status (dark or light) and depending of the status, it change it ! .

tell application "System Events"tell appearance preferencesget propertiesset currentValue to dark modeif currentValue is false thenset properties to {dark mode:true}else if currentValue is true thenset properties to {dark mode:false}end ifend tellend tell

That’s all ! This App is done ! Pretty easy no ?

It remain some work to do on this, especially a feature to do it totally dynamically with sunset/sunrise for instance or a preset defined by the user.

Also graphics are a bit basics, the App can be improved on this side !

Now it is all yours ! I will improve it on my side but if you like it and want to contribute by forking the repository please go ahead !

I assume Apple will think about a status bar on this maybe later but for now we need to sort this ourself !

I would like to thank you for reading my article, and I hope you will like Darky App and if you have ideas on how to do better, please comment below this article ! And of course if you like this article and thanks to Darky you have more time for clapping 👏 the post !

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store