Folder Action: print item(s) added to folder

Nov 04, '04 08:33:00AM

Contributed by: pianoroy

Here's a folder action script that will print any file(s) added to a folder.

  1. Copy and paste the code into Script Editor:
    on adding folder items to this_folder after receiving these_items
      try
        tell application "Finder"
          repeat with i from 1 to number of items in these_items
            try
              set this_item to item i of these_items
              set the path_string to this_item as string
              set the final_path to POSIX path of the path_string
              do shell script "/usr/bin/lp '" & final_path & "'"
            on error error_message
              tell application "Finder"
                display dialog "Error for item " & (this_item as string) ¬
                 & ": " & error_message buttons {"Continue", "Cancel"} ¬
                 default button 1 giving up after 120
              end tell
            end try
          end repeat
        end tell
      on error error_message
        tell application "Finder"
          display dialog error_message buttons {"Cancel"} ¬
           default button 1 giving up after 120
        end tell
      end try
    end adding folder items to
    
  2. Save as a Script
  3. Control-click (or right-click if you're multi-button enabled) on the folder you want to apply the script to, and select "Attach a Folder Action..."
  4. Select the script you just saved
That's it; to use, just drop a file into the print folder. Hope someone finds this useful!

Comments (20)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20041104011839378