Applescript and printing

Discussion in 'Mac Programming' started by Aouttier, Apr 14, 2016.

  1. Aouttier macrumors newbie

    Joined:
    Mar 3, 2016
    Location:
    Belgium
    #1
    Good evening,

    I have a little script which print a file (without opening it). The code looks like:

    Code:
    tell application "Finder"
        activate
        print document file PathFileDoel
    end tell
    PathFileDoel is the name of the file.

    Now, I want that the file to be printed double sided. What do I have to change to the code?

    Thanks in advance!
     
  2. 0d085d macrumors regular

    Joined:
    Apr 23, 2015
    #2
    You'll want to print via CUPS (the UNIX printing system):

    Code:
    do shell script "lp -d HP_LaserJet_52001 -o sides=two-sided-long-edge " & quoted form of (POSIX path of (PathFileDoel as alias))
    
    To find the name of your printer, open the Terminal application and type:

    Code:
    lpstat
    
    followed by enter.
     
  3. Aouttier, Apr 15, 2016
    Last edited: Apr 15, 2016

    Aouttier thread starter macrumors newbie

    Joined:
    Mar 3, 2016
    Location:
    Belgium
    #3
    Thank you for your reply

    Since I switched recently from Windows to Mac, I'm not a real expert in Mac, so forgive me my supplementary questions.

    Cups.... Is that something that I have to install?

    Does this also work with a networkprinter?
    --- Post Merged, Apr 15, 2016 ---
    Forget my former questions, after some surfing, I found that CUPS is standard installed on a Mac. I even found that I can address it with Safari ( http://127.0.0.1:631).

    But now, the command lpstat doesn't work. But, I can find the printer name on the site.

    How does my code have to look like. Now, I have and it doesn't work (the opened document in pages isn't printed):
    Code:
    tell application "Pages"
        activate
        do shell script "lp -d HP_LaserJet_500_colorMFP_M570dw__6C4329_ -o sides=two-sided-long-edge "
    end tell
    
     
  4. 0d085d macrumors regular

    Joined:
    Apr 23, 2015
    #4
    Your problem is that the lp command doesn't have anything to print. You need to pass it a filepath:

    Code:
    tell application "Pages"
        activate
        set filePath to path of document 1
        do shell script "lp -d HP_LaserJet_500_colorMFP_M570dw__6C4329_ -o sides=two-sided-long-edge " &
    quoted form of (POSIX path of filePath)
    end tell
    
    If that doesn't work, try running lp without any arguments in Terminal (just press ctrl-c after a few seconds to get the prompt back) then run lpstat again and see if it gets you the printer name. What you've got looks like it's probably right though.
     
  5. Aouttier thread starter macrumors newbie

    Joined:
    Mar 3, 2016
    Location:
    Belgium
    #5
    It worked! Thank you very much!

    But, now he's printing to the manual tray. How, do I have to switch the tray he's printing too?
     
  6. 0d085d macrumors regular

    Joined:
    Apr 23, 2015
    #6
    You'll need to add a -o media=Upper to the command. Change Upper to find the tray you want. Running lpoptions -p printer_name -l in Terminal might give you a list of available trays (under InputSlot) but this doesn't work for me when I try it.
     
  7. Aouttier thread starter macrumors newbie

    Joined:
    Mar 3, 2016
    Location:
    Belgium
    #7
    Thank you very much!

    My printer is also a Fax. Can I also send a Fax with CUPS?
     
  8. 0d085d macrumors regular

    Joined:
    Apr 23, 2015
    #8
    You need to find the queue name for your fax first.

    Run lp in Terminal. Give it a few seconds then press ctrl-c. Now run

    Code:
    lpstat -p -d
    It should give you a list of available queues. When you've found your fax machine, use the following:

    Code:
    do shell script "lp -d HP_LaserJet_52001_fax -o phone=01234567890 " & quoted form of (POSIX path of (PathFileDoel as alias))
     

Share This Page