Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Print file without opening

I am trying to print a file through apple script, in the end i want this file to be run when a rule in mail is triggered however at the moment I am just testing sections.

I was trying to emulate dragging and dropping the file to the printer.


When I run this script I get the error "Finder got an error: Handler can’t handle objects of this class." where am I going wrong, I am pretty new to apple script.


set theFile to "/Users/user/Desktop/print test.pdf"


tell application "Finder"

set sel to the theFile

open sel using POSIX file "/Users/user/Library/Printers/HP LaserJet 4000 Series (0001E66E3E6D).app"

end tell

MacBook Pro (13-inch Mid 2012), OS X Mavericks (10.9.4)

Posted on Jul 18, 2014 8:24 AM

Reply
6 replies

Jul 30, 2014 7:04 AM in response to andygodley

Ah a bit of a difference, no? 😉


I think I found the error, in the line

set theFile to ((path todesktop) astext) & "print test.pdf"

from my previous post the formatting got messed up. there should be spaces between to and desktop and as and text


so the line should be

set theFile to ((path to desktop) as text) & "print test.pdf"


Also you don;t need to do the

set sel to theFile

command you could just use theFile in the open command i.e.:

open theFile using -- rest of the line as is --


Finally any reason you are trying to print out the file this way and not use the print command or print through Preview? just curious.


regards

Jul 30, 2014 7:36 AM in response to andygodley

I have a default printer named Sammy in my System Preferences > Printers & Scanners configuration. The following will print a PDF on my Desktop to this default printer. I had to replace the clause without print dialog with its class representation to side-step AppleScript detecting a second command (print) name. Also, this approach does not permit the use of print properties such as copies, starting page, ending page, etc. Replace Sammy with your default printer name, not its path or .app extension.


set theFile to POSIX path of ((path to desktop) as text) & "re_format.pdf"


tell application "Sammy"


activate

print theFile without «class pdlg»


quit

end tell

Print file without opening

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.