Hot Folder Folder Action

Updating this with the -o raw lp option since I discovered that, without, it will default to whatever is providing default papersize. In my case US Letter. If that option does not work for you, naturally edit it out.

(*
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. 
*)

set send_raw to {"C3080__hold_"}

global send_raw

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

set this_folder to (choose folder)
set these_items to {}
tell application "System Events" to set these_items to every item of (this_folder) whose name does not start with "."
my do_thing(these_items, this_folder)

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

Leave a Reply

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