# Better blurring with Acorn and AppleScript

A few days ago I wrote a post about blurring personal information in screenshots by using Acorn. The technique I described, which uses Acorn’s Motion Blur filter, gave good looking results, but was a bit too fiddly with the clicking and the tabbing and the thing. At the end of the post I lamented my inability to script my actions to make them go faster and more accurately.

I wish I could do that initial blur through a script. I’ve looked through Acorn’s AppleScript library and the examples on Flying Meat’s site, but I don’t see how to choose a particular preset through a script. Similarly, I’d like to have a script that does the Fill… with Darken blending, but I haven’t found a way to do it.

I hoped that by acting incapable and pathetic, some of you would step up give me some help. But apart from Gabe telling me a faster—but, to my eye, less pleasing—way to do the blurring by hand, I heard nothing from any of you. I do and do for you people, and this is the thanks I get.

Since Acorn’s AppleScript library didn’t have what I wanted, I resorted to that last refuge of the scoundrel: GUI scripting. Here’s a script that applies a Motion Blur filter with a radius of 4 pixels and an angle of 135°.

 1:  tell application "Acorn" to activate
2:  tell application "System Events"
3:    tell process "Acorn"
5:        click
7:          click
9:        end tell
10:      end tell
11:      delay 1
12:      tell window "Apply Filters"
14:          click
16:        end tell
17:        click button "Apply"
18:      end tell
19:    end tell
20:  end tell


The script is tedious to write but is pretty easy to read. It works because I already have a preset for that radius and angle. Even though I may need to apply this filter several times, the script only needs to be run once; after the first run, the top item in the Filter menu, bound to ⌘F, will repeat the last filter used.

To handle the fill that I do after the blurring, I wrote this script for dark text on a light background,

 1:  tell application "Acorn" to activate
2:  tell application "System Events"
3:    tell process "Acorn"
5:        click
7:      end tell
8:      delay 1
9:      tell window "Fill"
10:        tell pop up button 2
11:          click
13:        end tell
14:        click button "OK"
15:      end tell
16:    end tell
17:  end tell


and this one for light text on a dark background,

 1:  tell application "Acorn" to activate
2:  tell application "System Events"
3:    tell process "Acorn"
5:        click
7:      end tell
8:      delay 1
9:      tell window "Fill"
10:        tell pop up button 2
11:          click
13:        end tell
14:        click button "OK"
15:      end tell
16:    end tell
17:  end tell


The only difference between the two is the type of blending done in Line 12.

The reasons behind all of these steps are given in the earlier post. The one-second delay you see in Line 11 of the first script and Line 8 of the other two is there to give Acorn a chance to display the window before we start trying to click on things in it. The value of one second was arrived at empirically: The script often failed when there was no delay, and it still failed sometimes with a half-second delay, but it never failed in my testing with a one-second delay. Not exactly rocket science.

I have the three scripts—called Motion Blur 4 135°, Fill Darken, and Fill Lighten, respectively—saved in ~/Library/Scripts/Applications/Acorn so FastScripts can find them and make them available in its menu when Acorn is active. They are bound to the keystroke combinations ⌃⌥⌘M, ⌃⌥⌘D, and ⌃⌥⌘L, respectively.

My process for blurring personal information in a screenshot is now this:

1. Set Acorn’s primary color to the background color near the text.
2. Select with the rectangular selection tool the character string I want to blur.
3. Press ⌃⌥⌘M to apply the Motion Blur once.
4. Type ⌘F to reapply the filter as many times as necessary to obscure the text.
5. Press ⌃⌥⌘D or ⌃⌥⌘L to fill in the transparent areas left by the blurring filter.

The steps go very quickly now and leave behind a blur that’s more stylish than a big black rectangle or the kind of fuzzball left by a Gaussian blur filter.