Hot Folder Folder Action

(*
strawhousepig.net

Hot folder action! The jokes write themselves.

Takes the name of the folder it is attached to and sends received items to the
corresponding printer.

How to: Find a place to keep a folder that is named as the printer ID (not the name), which
can be found using 'lpstat -v', or seen in the cups web interface, or as "Device name"
in the GUI printer settings, and attach this script to it as a Folder Action. The run handler
is here just for testing, but could be set-up to send files selected in the Finder.

I keep my hot folders in a child folder of the Desktop, so it's fairly convenient to drop
items into. If dropping isn't your bag, you could place the hot folder in ~/Library/PDF Services,
or write a seperate script or workflow in PDF Services to have the best of both worlds.
*)

on adding folder items to this_folder after receiving these_items
my do_thing(these_items, this_folder)
end adding folder items to

on run
set this_folder to (choose folder)
set these_items to {}
tell application "System Events" to set these_items to every item of (this_folder)
my do_thing(these_items, this_folder)
end run

on do_thing(these_items, this_folder)
repeat with i in these_items
set i to quoted form of POSIX path of (i as alias) -- Undo this and the shell scripting if you want to try the "System Events" route.
set _script to "lp -d " & name of (info for this_folder) & " " & i & "; mv " & i & " ~/.Trash/"
--log _script --for debuging
do shell script _script
-- tell application "System Events" to print i with properties {target printer:this_printer} -- Bugged. Does not work. *smh*
end repeat
end do_thing

Leave a Reply

Your email address will not be published. Required fields are marked *