I'm on a bit of an AppleScript kick lately. It's a frustrating language to use as it's often counterintuitive. I'm constantly looking up the right syntax to do things. But, it's a great way to patch little annoyances you encounter in Mac software.
The latest annoyance involves Tweetbot image windows. While I'm reading my timeline, I click on lots of links and images. After a while, I find I have a ton of image windows left over.
There's no good way to close all of those windows without quitting and restarting the app. Holding down ⌥ and clicking on the Window menu shows Close All bound to ⌥⌘W, but it doesn't work for me. The alternative is to click on each window and ⌘W on the keyboard, but who wants to do that?
I wrote a little AppleScript to do it. Tweetbot isn't strictly AppleScriptable, but using System Events and Accessiblity gets the job done. The script is a bit kludgy as the inner
repeat loop fails after closing three or four windows. To get around it, I wrapped it in a
try...on error block and repeat that until there's only one window left.
I've got this bound to ⇧⌘W using FastScripts.