The Robservatory

Robservations on everything…

 

A quick-toggle solution for OS X’s translucency feature

OS X includes—and enables by default—translucency, which gives you ‘wonderful’ effects such as this in Calculator:

This is just one example; lots of other apps (Mail and Messages, to name two) contain panes that become grossly distorted by background color bleed-through. I’m not sure who at Apple (Marketing?) thinks this feature is good for productivity , but I find it completely distracting.

As a result, I turn off translucency on every Mac I own. You can do so yourself in System Preferences > Universal Access > Display. Just check the Reduce transparency* box, and you won’t get any more bleed-through. (You’ll also get a solid Dock, and perhaps the world’s ugliest Command-Tab task switcher. Such is the cost of usability.)

* It’s ridiculous that Apple calls this transparency, which is defined as “the condition of being transparent,” and being transparent means being see-through, clear, invisible, etc. This is clearly translucency, or “allowing light, but not detailed images, to pass through.” But I digress…

However, when writing for Many Tricks or Macworld, I often need to take screenshots. And because most users won’t disable translucency, I prefer to take those screenshots with translucency enabled, so that they’re closer to what most users might see. That means a trip through System Preferences to toggle the checkbox, which gets annoying after the second or third time you’ve done it.

There had to be an easier way—and after some missteps, I eventually found it.

My first thought was to write a simple shell script that toggled the defaults value (reduceTransparency in com.apple.universalaccess) for translucency, then trigger that shell script via the keyboard.

While this worked, it seems that triggering the setting via System Preferences does some behind-the-scenes magic I couldn’t mimic in Terminal (even when relaunching the Dock and SystemUIServer). As a result, I was sometimes left with a translucent Dock and non-translucent menu bar…or some apps with translucency, some without. Not good.

So I went old school, and resorted to GUI scripting in AppleScript, and it’s working perfectly. Sometimes, old school is the best school.

Here’s the final script I wound up creating in Script Editor. Note that I am far from an AppleScript expert, so I expect there are lots of ways this could be improved. But it works, and seems to work well.

(Many thanks to Doug Adams for the reveal anchor help; I couldn’t figure out how to refer to a specific panel in the Accessibility pane, and he came through with the solution!)

Everything other than lines 15 to 24 is completely optional—all that code does is handle the case where you toggle translucency when System Preferences is already open on some other panel. If that’s the case, the script will remember which panel you were on and switch you back there after the toggle. If you don’t care about that, then you can just use lines 15 to 24 and the script should still work fine. (As a bonus, the script is much faster if it doesn’t have to check and store the current state of System Preferences.)

To test this script, you’ll be asked to add Script Editor to System Preferences > Security & Privacy > Privacy > Accessibility. Once you’re sure it’s working as you expect, save it as an application; I named mine ToggleTranslucency.

The first time you run your new app, you’ll get an error:

Just like Script Editor, you need to add your final compiled app-script to that same Accessibility area of the Security & Privacy System Preferences panel. OS X even helpfully adds it for you, but it won’t grant the permission. It not-so-helpfully uses an unexpected name; here’s how it looked on my Mac:

That “6A2F…” monstrosity is my ToggleTranslucency script; check the box, and from now on, the script should work without intervention. (I have no idea why it uses a weird long string instead of the app’s name, but it does.)

For fast access, you could put your app-script in your Dock, or into a Finder’s toolbar, or launch it via Spotlight. But I like keyboard shortcuts, so I assigned* Shift-Option-T to run my ToggleTranslucency app-script.

There are any number of ways to launch an app via a keyboard shortcut—I used our own Butler, but that’s like using a 500 pound sledgehammer to drive a nail if all you want is to launch an app. Keyboard Maestro and BetterTouchTool will also do it, and I’m sure there a couple of dozen other solutions. Find one you like and use it.

Now when I need to toggle translucency on for a screenshot, it’s a quick keyboard shortcut away. Once I’m done with the shot, I can banish translucency via that same shortcut. Fast, simple, and oh so much nicer than navigating deeply into System Preferences.

Leave a Reply

The Robservatory © 2017 Built from the Frontier theme