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.


5 Responses to “Scanners live in vain”

  1. Clark says:

    Doesn’t the Brother have an associated TWAIN driver? If so you should be able to scan in many applications that might be a tad more convenient. (Maybe no, I don’t know your workflow) If there is a TWAIN driver try opening /Applications/Image Capture and you might find it a bit more convenient for scanning. And no Applescript required.

  2. Carl says:

    In Preview.app, you can bring up this same scanner app by going to the File menu. In fact, I didn’t even know there was another way to bring it up.

  3. Dr. Drang says:

    Most of the time, scanning into an app wouldn’t be more convenient because I simply want to save the file into the appropriate project folder. There are, however, times when I scan smaller sheets of paper, and the scanner puts them in letter-sized document. Those are times when scanning into Preview for cropping would be a time-saver.

    I confess that I’d gotten so used to scanning from the Windows machine and transferring the files to my Mac that I’d forgotten I could scan directly into Preview and other applications. (Come to think of it, I haven’t had a scanner connected to a Mac in almost 20 years. Crikey.) That’s certainly faster than the multi-step process I mentioned in the post (which I’ll have to amend), although not quite as fast as the AppleScript. Thanks to Clark and Carl for reminding me.

  4. JG says:

    Any reason you can’t use Image Capture.app?

  5. Dr. Drang says:

    I can use Image Capture, JG, but I don’t know what advantage there is to it. It’s faster than the five-step process, yes, but not as fast as launching the standalone app through AppleScript. And when IC is done, I have a file on my disk, just like with the standalone app. It does, at least, remember my last settings, which is more than I can say for Preview.