Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Aouttier

macrumors member
Original poster
Mar 3, 2016
42
0
Belgium
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!
 
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!

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.
 
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?
[doublepost=1460746176][/doublepost]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
 
Last edited:
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?
[doublepost=1460746176][/doublepost]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

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.
 
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?
 
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?

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.
 
Thank you very much!

My printer is also a Fax. Can I also send a Fax with CUPS?
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))
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.