Anger, magic, and AppleScript

Yesterday was a day of great frustration in using my Mac. After couple of hours of swearing, I deleted a utility program for what were almost certainly irrational reasons and then wrote an AppleScript to replace its functionality.

I was annotating a set of drawings and photographs of a building using a combination of Preview, OmniGraffle, and Acorn. The work involves a lot of zooming in to make sure the annotations line up with the architectural feature and zooming out to make sure the annotations are nicely spaced and easy to read. The frustrations arose because pinch-to-zoom had stopped working. I did all the usual things: quit and relaunched the programs, unset and reset the pinch-to-zoom feature in System Preferences, and rebooted the computer. And I did these in different sequences, too. For example, I tried unsetting pinch-to-zoom, then rebooting, then resetting pinch-to-zoom. Nothing worked.

I quit BetterTouchTool. This is not an essential utility for me; I’ve been using it lightly for a couple of months but only because it came with Setapp. It seemed logical that an app that redefines how the trackpad behaves could be interfering with pinch-to-zoom, even though it never had before. But quitting BetterTouchTool didn’t work either, even after another reboot.

It was at this point that I descended into irrationality. I uninstalled BetterTouchTool. Now I know what you’re thinking, because I was thinking it, too. There’s no way an app that isn’t running can affect my computer. It’s just a bunch of bits on the hard disk, like any other file. But just the same, I uninstalled BTT, deleted its preferences, and rebooted. And pinch-to-zoom started working again. It’s still working.

Coincidence? Magic? Some weird digital placebo effect? I have no idea, I’m just happy to be able to zoom freely again.

Uninstalling BTT was not a great loss for me. I’m much more of a keyboard shortcut guy than I am a trackpad gesture guy. But there was one gesture I’d built that was useful: it arranged BBEdit and Terminal windows to convenient sizes in the right half of my screen. While I didn’t care how that arranging was triggered, I did miss the rearranging itself. So I wrote an AppleScript to do it and saved it as a Keyboard Maestro macro.

Here’s the macro, which I’ve saved in the Global group and which is triggered by ⌃⌥⌘W:

Arrange BBEdit and Terminal Windows macro

It’s just one step with this AppleScript:

applescript:
1:  tell application "BBEdit"
2:    set bounds of front window to {1585, 45, 2495, 850}
3:  end tell
4:  
5:  tell application "Terminal"
6:    set bounds of front window to {1585, 855, 2495, 1435}
7:  end tell

The window bounds are tuned for my 2012 (non-Retina) 27″ iMac with the Dock on the right side. When it’s run, the BBEdit and Terminal windows look like this:

Rearranged BBEdit and Terminal

I use the space off to the left for reference material as I write or code: drawings, photos, documentation, web pages, whatever.

A more general solution would get the bounds of the whole screen and do some math to figure out the window coordinates. But I wanted a quick solution that would get me back to work, so I resized the windows by hand, used AppleScript and a call to

applescript:
get bounds of front window

for each app, and then tweaked those results by a few pixels to get the coordinates used in the script.

As for the zooming problem, I have no intention of investigating what happened or why. As long as pinch-to-zoom is working, I’ll leave well enough alone. But if magic works in the Apple world, I may invest in a silver-haired voodoo doll and see if a few well-placed pins will encourage Craig Federighi to improve macOS reliability.