Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Folder Action: print item(s) added to folder System
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!
    •    
  • Currently 2.00 / 5
  You rated: 4 / 5 (4 votes cast)
 
[11,582 views]  

Folder Action: print item(s) added to folder | 20 comments | Create New Account
Click here to return to the 'Folder Action: print item(s) added to folder' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Droplet?
Authored by: sinjin on Nov 04, '04 10:18:26AM
Oh, I do find this useful! I've been trying to put together a similar script (more below). Is there a reason why you chose to use a folder action for this instead of making it a droplet application? Just curious. I think someone could change the "on adding ... end adding" wrapper to "on open ... end open" if they preferred droplets and everything should work just the same.

What I'd like is something that helps me to duplex print piles of pdfs on my non-duplexing printer. I've created "Evens" and "Odds" settings for my printer, but it's tedious to babysit, say, 20 print jobs.

The script I've put together so far (non-functional) shares a lot with yours and relies on GUI scripting of Preview (because it and Acrobat Reader are non-scriptable). The theory is that I should be able to drop all the pdfs I want onto the droplet, all the evens get printed out and then I return to whole pile to the paper tray and hit a button to continue printing the odds.

Insight or alternatives would be greatly appreciated!

[ Reply to This | # ]

Droplet?
Authored by: LegoEvan on Nov 04, '04 11:04:57AM

You should definitely have the droplet print a blank page between each document, because there are situations where you'll print the last odd page of a document on the back of the first even page of the next one. In fact, you may want to print odds first (you can never have more evens than odds)

Just a thought



[ Reply to This | # ]
Odds or Evens?
Authored by: sinjin on Nov 04, '04 01:08:39PM
Good point. I've been going with evens in reverse first then odds. I'll need to print a spacer page for each odd-numbered document either way, though, won't I?

In looking at kirkmc's post below I see that I may be wasting my time trying to decipher the GUI hierarchy of Preview. If I can script lp to do odds/evens and reverse order it would be a lot more useful (could do a wider range of file types) and be a lot faster (the GUI script required a lot of time wasting kludges).

[ Reply to This | # ]

Droplet?
Authored by: thavron on Dec 12, '04 08:35:32PM
for even/odd, use:
lp -P 1,3,5,7,9,11 filename


[ Reply to This | # ]
Folder Action: print item(s) added to folder
Authored by: LegoEvan on Nov 04, '04 11:12:02AM
Before I go and set up a guest account and do a variety of things in order to get it to work... Does anyone know if the folder actions activate if someone
 scp
s or
ftp
s something in? I can't show my printer to my roommate across the network without letting all of the dorm print to it.

[ Reply to This | # ]
Folder Action: print item(s) added to folder
Authored by: kirkmc on Nov 04, '04 11:28:30AM

I haven't tried the script, but if it's using the lp command it won't print "any" file. It will print txt, pdf, rtf, jpg, tiff, and some other graphic formats. It won't, for example, print Word, Excel or AppleWorks files (unless they are in one of the formats mentioned earlier).

---
Read my blog: Kirkville -- http://www.mcelhearn.com
Musings, Opinion and Miscellanea, on Macs, iPods and more



[ Reply to This | # ]
Folder Action: print item(s) added to folder
Authored by: gneagle on Nov 04, '04 01:07:29PM

Why wouldn't you just use a Desktop Printer for this? In the Printer Setup Utility, select a printer, and then choose Printers->Create Desktop Printer, or simply drag the icon of the printer to the desktop. You can then drag documents to the printer icon to print them.



[ Reply to This | # ]
Folder Action: print item(s) added to folder
Authored by: Jon on Nov 04, '04 01:15:05PM

...or just drop it on the already existent desktop printer in ~/Library/Printers



[ Reply to This | # ]
Accountability, perhaps
Authored by: sinjin on Nov 04, '04 01:33:08PM
I'm not exactly sure either but my guesses are the above script would be useful if 1. you don't want to launch all the applications associated with the files being printed (I believe the desktop printer will, lp won't) and 2. if part of the reasoning or workflow is to have accountability for the documents you've printed, i.e. a quick glance at the folder(s) with the documents in it/them tells you that you've already printed them so go look for the hard copy. Something like that.

[ Reply to This | # ]
How I found this useful (from the script's author)
Authored by: pianoroy on Nov 04, '04 01:43:06PM

The reason I wrote this was because I have a network with my own computer (connected to a printer) and a wireless PC laptop. I have SAMBA running on my mac, but I haven't been able to get the printer settings right so the PC laptop can print through SAMBA.

So I made the Folder Action as a workaround, so the PC user can just drop a file into "MacComputer > Shared Items > PrintFolder" and it'll automatically print.

Of course, it only works with the CUPS-enabled file types (postscript, raw postcript, PDF, text, rtf, images, and a few others). So if the PC laptop user wants to print, say, a Word file, they have to print it to file (PDF or PostScript) and then drop it in the PrintFolder.



[ Reply to This | # ]
A laurel, and a hearty handshake to anyone that can:
Authored by: Drewstre on Nov 04, '04 02:34:45PM

Hiya-
I need a way to print multiple files in alphanumeric order. Say I drag these files to Print Center:

Filename_001.eps
Filename_002.eps
Filename_003.eps
etc...

They print in a seemingly random order. I have been looking for a way to correct this for months and months.

The main approach I've been trying: make a droplet that will store all dropped filenames in an array, sort the array, and send the files in order to Print Center, with a slight delay between them, so Print Center will queue them in order. But I haven't the skills to code it, nor the time to learn them, at this time.

Any takers?

Thanks,
Drewstre



[ Reply to This | # ]
Ideas for you
Authored by: sinjin on Nov 04, '04 02:47:41PM
You have a script started? Sound to me all you need to do is add this example sorting routine to it and put a delay line in an appropriate part of the printing loop, like just after each print command goes out.

Hope that helps.

[ Reply to This | # ]

Ideas for you
Authored by: Drewstre on Nov 04, '04 03:51:03PM

Hiya-
Thanks!
(How did I miss that?)
I'll play around with it...

Thanks again!
:^Drewstre



[ Reply to This | # ]
sorted files
Authored by: ngb on Nov 05, '04 03:22:51AM

Another non-scripted approach you might try is selecting the files while in column view before dragging the files to the desktop printer.

I've found that selecting files in any other view (even list view) does not selected them in a sorted way.



[ Reply to This | # ]
Folder Action: print item(s) added to folder
Authored by: mmulhern on Nov 04, '04 04:03:39PM

Doh! why didn't I do this months ago. I've been printing from my VPCs in Postscript (save to file), then switching back to my Mac's desktop and printing from Preview.

I'll give this a go this weekend.



[ Reply to This | # ]
more options: Folder Action: print item(s) added to folder
Authored by: dubmaster on Nov 04, '04 05:01:51PM

I don't need this anymore, but I had once a set-up where I couldn't do printer sharing (think someone at home used a very old system). I don't think I have the script anymore, but what I did was to share the folder using share points and I added to the script a function to delete the files, after printing.
If you want to print word documents for example, you can insert a loop, which checks for the exctension/creator and then opens Word. calling system events so you can print even those files.
If ever I find that script I will post it as well.

---
DubMaster
--
Rehab is for quitters!



[ Reply to This | # ]
Folder Action: print item(s) added to folder
Authored by: vancenase on Nov 04, '04 05:20:31PM

could something similar to this (a folder action) be used in a folder that I use for my default Safari downloads?

for example, if i download a file using Safari (which defaults to a folder ~/Downloads), and it's a PDF file, could a folder action move it to ~/Downloads/PDFs automatically?



[ Reply to This | # ]
Folder Action: print item(s) added to folder
Authored by: vancenase on Nov 04, '04 06:56:50PM

found a post where i requested this before! neat! :)



[ Reply to This | # ]
redirect scripts
Authored by: sinjin on Nov 04, '04 08:34:25PM
Absolutely. You could use this somewhat complex script and modify it to your needs.

OR take the simple one below that moves EVERY file you add to a folder and wrap a conditional around it that only moves pdfs. See Apple's Applescript samples for help on that last part.


on adding folder items to this_folder after receiving added_items
  repeat with each_item in added_items
    tell application "Finder"
      move each_item to "Path:to:new:folder:" replacing no
    end tell
  end repeat
end adding folder items to


[ Reply to This | # ]
redirect scripts
Authored by: vancenase on Nov 05, '04 02:39:41PM

thanks! i think i'll take a stab at this!



[ Reply to This | # ]