fScanX Automator Action: Copy Documents

This example creates an application which scans a document to a temporary file, prints it, and deletes it.

Start by creating an application workflow. First we want to get a unique file name, in a location that the system will periodically clean out. Find and add the "Run Shell Script" action (by typing its name into the search field then dragging it into the workflow area), configuring it with the script as shown below:


You can copy & paste this script:

mktemp -u /tmp/fscanx-print-XXXXXX

Add the fscanx action and configure it (probably choosing to "Show this action when the workflow runs" from the "Options" menu).

Next we will tell the Preview application to open the scanned document, and send it the command-P shortcut to get it to print the document. Find and add the "Run AppleScript action, and configure it with the script shown:


You can copy & paste this script:

on run {input, parameters}
  tell application "Preview"
    activate
    open input
    tell application "System Events"
      tell process "Preview"
        delay 0.1
        keystroke "p" using command down
      end tell
    end tell
  end tell
  return input
end run

Finally, we want to delete the temporary file. (The system would eventually clean it up, but we do it right now to be neat.) Find the "Run Shell Script" action again, and add it again at the end, configuring it with the script shown, and making sure to select "as arguments" for the input style:


You can copy & paste this script:

rm "$1"

Save this, and you have an application that lets you quickly copy a document.

Alternatives that don't work (or don't work well)

This workflow not only has the most steps of any developed so far, but it is the result of some trial and error. There are other approaches that should work, but are not useful. The information that follows is not needed to use this example, but might be of interest if you're trying to learn more about Automator and scripting.

There is a "Print Images" action that should be ideal for this, but it has several problems:

  • If you have never changed your print settings from defaulting to the last printer used, it will not be able to find a printer. You must use System Preferences to specify a default printer. (You can then switch the default back to "last used", you just have to specify it once.) Even though the action lets you choose a printer, it will not work unless you do this.
  • It does not provide you with access to any of your printer options. No choice of tray, no chance to specify double-sided printing.
  • It makes a poor choice for paper tray, rather than "automatically select" which works pretty well on most printers, it prints to the first tray, which is often the manual-feed or multi-purpose tray.

You should be able to use a simpler AppleScript that just tells Preview to print the document. But Preview will not show the print settings dialog. (It will ignore the "with dialog" option.)

You can use a simple AppleScript to ask Adobe Reader to print the document, and Reader will display the print dialog and nicely close its window after printing. But in Adobe Reader X, the print dialog is a user-interface abomination that not only hides your printer options, but chides you if you try to access them.