Saturday, 9 February 2013

Use Folder Actions to Automatically Print Items Added to a Folder, Google Drive or Dropbox

I required a means to automatically print invoices saved by SageOne to my Google Drive.

  1. Open AppleScript Editor
  2. Copy the following code to the code window and compile
  3. Save the script to \Library\Scripts\Folder Action Scripts\
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

Now that you have created your script it is easy to apply it as a Folder Action to the folder of your choosing.
  1. Ctrl-Click (or right-click) the folder you wish to apply the Folder Action to, and Select Folder Actions Setup
  2. In the new windows select the script you created above and click Attach
  3. Add a file to the folder to test.
If all is well your file will print from either your current Default Printer, or the Last Used Printer.

Simple!

NOTE: This has been tested ONLY on OS X Mountain Lion.
If you have tested this script on other version of OS X please let us know it's compatibility!

0 comments:

Post a Comment