Scanners live in vain

I’ve been using the scanner at work a lot recently and decided I was spending too much time clicking and dragging. I wrote a little script to cut down on the nonsense.

What we have isn’t a dedicated scanner; it’s one of those multifunction copier/printer/scanners from Brother. We’re a small place, and don’t need much capacity, so it works well enough. What doesn’t work very well is the software that came with it. The software is Windows-only, of course, and it’s installed on a Vista machine in the same room as the scanner. Up until recently, I’d run the scanner from the Vista machine, save the scans to its Public folder, then go back to my Mac and copy them to my disk. I might end up doing this more than once because the scanner software makes it easy to get the wrong output. Wrong resolution, black-and-white when you want color, a PDF when you want a JPEG, etc.

The scanner driver on Mountain Lion, in contrast, puts all the controls in a simple layout that’s easy to read and adjust:

Scanner controls

The annoying part of scanning from the Mac, though, is getting to the scanner driver in the first place.

Print & Scan preference pane

The typical procedure is:

  1. Open System Preference.
  2. Switch to the Print & Scan pane.
  3. Choose the scanner from the list of devices.
  4. Click the Scan side of the Print/Scan lozenge.
  5. Click Open Scanner…

Ugh.

Update 1/30/13
Well, as Clark and Carl were too polite to say in the comments. this 5-step process is not typical for anyone paying attention. You can bring up the scanner driver from within several apps, Preview being the most prominent. The AppleScript described below is faster than scanning into an application if you don’t want to crop or otherwise edit the scan (my usual case) but not as fast if you do (my non uncommon case).

Update 1/30/13
After scanning a few documents into Preview this morning, I must say the experience isn’t as nice as I’d hoped. Every time I open the driver, the settings are at a default state that I would never use: 100 dpi A4-sized TIFF. I assume there’s some way to change the defaults and make them stick, but I much prefer the way the standalone program works—it remembers my settings from last time and starts from there.

After going through these steps too many times, I realized that since there’s a new icon in the Dock when the scanner driver is open, there must be an application associated with it that, if I was lucky, could be controlled by AppleScript.

I was lucky. The application has the same name as the scanner and the driver can be opened in one step with this AppleScript:

applescript:
1:  tell application "Brother MFC-8680DN"
2:    get visible of front window
3:    activate
4:    tell application "System Events" to keystroke "3" using command down
5:  end tell

When the application opens, it doesn’t present the scanner window, it starts off with the print queue window.

Brother print queue

To open the scanner window, we have to either click the button in the upper right corner, choose a menu item that does the same thing, or type the menu item’s keyboard shortcut, which is ⌘3. As you can see in Line 4, I used System Events to simulate the latter.

You’re probably wondering why Line 2 is there. What’s the point of learning the visibility of the front window if we never use it? Well, children, I don’t want to burst your bubble, but programs don’t always work the way they’re supposed to. For reasons known only to the gods, the activate command doesn’t bring the Brother MCFC-8680DN application to the front. And if it’s not at the front, the keystroke simulation in Line 4 does nothing. I wanted to figure out why this was, so I decided to add debugging code to the script. The first thing I thought of was to check the visibility of the first window that appears, and, amazingly, adding that debugging line fixed the problem. Sometimes it’s better to be lucky than smart.

Have I tried to understand this bizarre behavior? Hell, no! That might spoil the magic juju, and then where would I be?

I saved the script under the name “Scanner” in my ~/Library/Scripts folder, and now I have an item in my FastScripts menu that brings up the scanner driver in one step. I’m tempted to rename it “Cranch,” but that seems too obscure, even for me.