Quickly toggle Invert colors on OS X

tl;dr — download the app here.

(If you are on a slow machine, this may not work for you. But fear not, read on and you can build one that does.)

Some times,

DarkMode

just make a lot more sense to me than,

NormalMode.

If you have times like these too, OS X has an Invert colours option. Unfortunately it is buried layers inside System Preferences.

I need to switch between the modes often, depending on the kind of work I am doing. So I wrote an executable script (another word for an app) which can be run directly from spotlight.

invert_execution

Download the app from here. Place it anywhere on your system you want (provided that location is indexable by spotlight). You can be creative and rename the app anything you want. Just make sure that name is unique enough to come up on top in spotlight.

Since this app momentarily takes control of your system, the first time you try to execute it you will be asked to set permission for it. Open System Preferences > Security & Privacy. Here you will see the app listed.

  • Trust me
  • Unlock preferences
  • Check the app

Screen_Shot_2014-11-14_at_10_59_24_am

Unless you do not trust me, this should do it, go ahead and have fun. If you are suspicious of me, lets build one together :]

Launch ‘Script Editor’. This is the IDE we will use to write, compile and execute our script.

First, lets try and get our script to open the System Preferences window and navigate to Accessibility screen. Type in this code:


tell application "System Preferences"

activate

set the current pane to pane id "com.apple.preference.universalaccess"

end tell

Hit the play button on top to execute the script. Unless you had a monkey on your keyboard, this should open the system prefs and navigate to Accessibility(historically referred to as universal access) screen.

Next, lets look for the ‘Invert colors’ checkbox and toggle it.


delay 0.1

tell application "System Events"

tell process "System Preferences"

if (exists checkbox "Invert colors" of window 1) then

click checkbox "Invert colors" of window 1

end if

end tell

end tell

You will notice we put up a delay, this gives time for OS to actually finish launching System Preferences.

In case you are on a slow machine you may want to change this to a higher value.

Run it again, if everything goes as planned, you should see your world with inverted colours now. But we still have the system prefs open. Lets add code to close that as well.


tell application "System Preferences"

quit

end tell

 

The script is now ready, all we need to do is create an Application from it. In Script Editor, select File > Export… Give your app a name. Under File Format change ‘Script’ to ‘Application’. Done.

If you modify this script to do other cool things with the system prefs, do let me know.

Advertisements

One thought on “Quickly toggle Invert colors on OS X

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: