6 Replies Latest reply: Jul 30, 2014 7:36 AM by VikingOSX
andygodley Level 1 (0 points)

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)
  • Frank Caggiano Level 7 (25,715 points)



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

    Finder doesn;t like posix paths


    You'll need to change the path for the application you are using to open it also.


    Using POSIX file should convert it so on second thought that part should be fine.

  • andygodley Level 1 (0 points)

    Thanks, tried that but it didnt solve the problem. I don't think the problem is with assigning the file path to the variable but with the printing of it to a specific printer.

  • Frank Caggiano Level 7 (25,715 points)

    Interesting. You're getting the same error after the change?

    Without that change i get the same error as you with the change it works for me.



  • andygodley Level 1 (0 points)

    no I get this error instead


    Expected “,” but found identifier.

  • Frank Caggiano Level 7 (25,715 points)

    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.



  • VikingOSX Level 6 (15,671 points)

    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"


      print theFile without «class pdlg»


    end tell