Reputation: 689
First up, I am no Applescript guru. I've just done a LOT of Googling to find out this much.
I've added the following script into a Hazel rule in an attempt to print a PDF file that Hazel has identified.
tell application "PrinterProxy"
activate
print theFile with properties {target printer:"Blah"} without print dialog
end tell
The actual printer name I've used is way longer and is the full name of a network printer.
When this rule executes, I get two Applescript error pop-ups, both of which simply say "Print service not available". I'm assuming that's one each for the activate
and print
verbs.
I then discovered if I manually launch the print queue window for the printer, the script works perfectly. Now I cannot figure out how to script that queue to open. Any time I mention it by name as an application, the Applescript compiler prompts me to find it in a list (the same list that Open Dictionary provides) and then changes it to "PrinterProxy" which achieves nothing for me.
Is there a way to open that window from the script, or is there another way to queue it without the window open? It seems odd that the window should need to be open when any app can print to the queue without it.
Upvotes: 1
Views: 1896
Reputation: 689
Oh, my! I just got it to work completely by accident. You know how I left out the actual printer name for brevity above? Yeah, turns out that's where the problem was!!
If you get the name of the printer wrong, then the list is presented for you to choose from and – annoyingly – this anonymises your selection. If you get the name exactly right – which in my case meant the correct use of quote characters (sigh) – then it does not get replaced and it works a treat.
Here's my final code:
tell application "Brother HL-5240 series @ Elli’s Big Mac"
activate
print theFile without print dialog
quit
end tell
Note that darned ’
character that Apple so thoughtfully put in the printer name for me. Stupidly, I had typed out the name with a '
character instead. I'm really going off smart quotes!
Also, note the quit
line which closes the print queue window. There's apparently a bug which stops it auto closing after being referenced by certain activities, which seems to include my script. See here: https://discussions.apple.com/thread/4156725?start=0&tstart=0
Upvotes: 1