Automator won't pick printer

Hello all. New member here, and a total noob when it comes to scripting, automator, etc. Looking for help in automating a printer task.

I have an automator task that triggers weekly. I want it to print a “test page” in color to keep the print heads from clogging up. I have two printers, a HP laserjet (my default printer) and an HP color printer.

The automator task fires at the correct time, based on a calendar trigger. It prints the correct document, but always prints to the laserjet instead of the color printer.

In the “Print Finder Items” dropdown, I have the HP Envy selected. Even if I run the script from automator, it doesn’t print on the color (non-default) printer.

What am I doing wrong?

I should add that the color printer goes to sleep after 15 minutes, but even if I wake it up, automator prints to the laserjet.

Thanks in advance,

George

George, you don’t say what version of MacOS you’re running, but here’s a possibility. I’m on Sonoma 14.7 and in System Settings there is a setting for printers that (on my system) looks like the attached screenshot. It’s possible, that regardless of the setting in Automator, the MacOS will always select the last used printer unless this printer setting is changed. Just a thought.

Thanks for the reply, and I think you’re right.

I’m running Sequoia 15.0.1.

My printer settings are to have the laserjet the default printer.

I wonder if it would be possible to script a change to the default printer before printing, and then switch it back.

Just to be clear this is way beyond my capabilities, which is why I’m here, LOL.

You can probably add this shell script, which sets the default printer:

lpoptions -d you_printer_id_not_its_ui_name

I’m sure you’ll need more info on this, which I don’t have time to add right now… Maybe others will chime in.

1 Like

Thank you! I’ll give it a shot!

1 Like

To follow up on @leo_r’s suggestion…

There are a couple of commands that allow you to print stuff as well as specify a printer… specifically ‘lp’ or 'lpr' to print files, and ‘lpstat’ and ‘lpoptions’ to gather information and manage things. You can see what printers are available with ‘lpstat’.

For example, in the Terminal, you can type this to see the printers that are available and enabled and which is the default:

lpstat -p -d

You should then be able to print a pdf with a command like this. Note, I’m guessing at what the name of the envy printer is but the above command should provide the proper string. I think that it is case insensitive.

lp -d hp_envy_photo_7800_series filename.pdf

An applescript command to run this might be:

do shell script "lp -d hp_envy_photo_7800_series filename.pdf"

Note that your printer probably knows how to print pdf files without being open in an application. I’m not sure whether this will work with a word document. So, assuming that this can be made to work, it might be worth saving your test document as a pdf.

Also, there are several posts and threads on this site that discuss how to make some of these commands work. If you search the site for lpstat or lpoptions, you can browse through them.

The key thing though is to see whether you can work with your printers via the command line. Try launching Terminal (inside /Applications/Utilities) and typing lpstat -p -d and then ‘return’.

Hopefully, you’ll get a result like this but without the ‘paused’ — I don’t do a lot of printing :slight_smile:

% lpstat -d -p
system default destination: Brother_HL_2270DW_series
printer Brother_HL_2270DW_series disabled since Thu 18 Mar 13:33:17 2021 -
Paused

Then let us know what the result is and maybe we can walk you through this.

1 Like

George, were you able to come up with a solution. I’ve tried a few of the suggestions posted here and have been unable (so far) to end up with something that both selects the printer and then prints the file.

Well, yes, and no.

I actually created three automations.

  1. Set default printer to my color printer at a specified time.
  2. Two minutes later retrieve the page and print it.
  3. Two minutes later, reset default printer to my laserjet.

Seems to work OK on a test.

I’ll check it again tomorrow AM.

Thanks for the suggestions and help!

1 Like

I’d be interested in seeing a screen grab of the Automator (as you did in your very first post here). I’m still learning AppleScript, and the folks here have helped me a lot since I joined. I’ve got endless examples of things that I can now do via AppleScript, but the Automator is still a work in progress.

First of all, using terminal, get a list of printers you have on your mac.

type: lpstat -p

Then, open Automator and create a calendar event. Add shell script to set the printer you want to be the default.

Save this, and it’ll appear in the calendar app.

Then using a script, print the selected item:

  1. Open Automator:

• Navigate to Applications and open Automator.

  1. Create a New Calendar Alarm:

• Select New Document and choose Calendar Alarm as the type of workflow. This will allow the action to be triggered by a calendar event.

  1. Add “Get Specified Finder Items”:

• In the search bar on the left, type Get Specified Finder Items and drag it to the workflow area. This is where you will specify the file you want to print.

• Click Add and navigate to the document or webpage you want to print weekly.

  1. Add “Print Finder Items”:

• In the same search bar, search for Print Finder Items and drag this action below the previous one. This action will send the file to the printer.

  1. Save the Workflow:

• Save the workflow with a relevant name like Weekly Print. When saved as a Calendar Alarm, it will automatically create an event in the Calendar app.

  1. Set Weekly Trigger:

• Open the Calendar app and find the new event. Double-click the event, and set it to repeat weekly on your desired day and time.


Finally repeat step 1 (creating a 3rd script) resetting the OTHER printer as default.

You’ll have 3 scripts appear in the Calendar.app on one day. Change the triggering time for the first script to whatever you want, and then, space the remains two about 2 minutes apart.

It worked for me this AM.

1 Like

Worked fine this morning. Default printer set to color.

1 minute later - page printed.

2 minutes later - default printer set back to laserjet.