Safari Print Dialog is not reacting to any action

I’m automating downloading invoices from a website (Obsidian) using Keyboard Maestro. The current sequence of actions is:

Summary of Keyboard Maestro Actions

  1. Open a specific URL (Obsidian Billing page) in Safari.
  2. Wait for Safari to load (3 sec).
  3. Execute JavaScript in Safari to click the button on view the invoice list.
  4. Wait again for the next page to load fully (3 sec).
  5. Execute JavaScript in Safari to click a button to select the latest invoice
  6. Wait once more (3 sec).
  7. Execute JavaScript to click “Print invoice,” opening the Safari Print Dialog. (There is no option to download the invoice)
  8. Pause for 2 seconds to ensure the Print Dialog is fully visible.

My issue

  • After the Safari Print Dialog appears, I want Keyboard Maestro to select “Save as PDF” automatically.
  • However, no Keyboard Maestro action (Keystroke action, AppleScript keystrokes, or Click at Found Image) has worked reliably to trigger “Save as PDF”. I have created a Keyboard shortcut in the system settings for calling Save as PDF. When a keystroke action calls this shortcut nothing happens.
  • It seems the Safari Print Dialog prevents Keyboard Maestro’s input from being processed until the dialog is manually dismissed. After dismissal, the queued input occurs too late. I created a test macro triggered by a keyboard shortcut calling a keystroke action with the Save as PDF shortcut. That works when I trigger it via its shortcut in the dialog.

I’m looking for a robust and reliable method to have Keyboard Maestro automatically select “Save as PDF” from Safari’s print dialog.

Does anyone know why Safari’s print dialog is blocking Keyboard Maestro automation, and how I can reliably automate selecting “Save as PDF”?

Because the Print dialog is a consistent size, why not just use mouse move/click at a location from the top left (or whatever) corner of that window? The small arrow next to the PDF button will always be at the same location in that dialog.

You might then be able to send the keystrokes for "Save as PDF" to activate the menu item, but if not, just execute another "move and click" action, but this time from the mouse's current location, and move it down and over a bit until you click that menu item.

-rob.

Or just use the old trick of defining the Cmd-P hotkey as a keyboard shortcut to "Save as PDF" in the keyboard preferences, as discussed here among many other places. Then you can trigger it in KM by sending the Cmd-P hotkey twice.

They said they tried that and it didn't work:

-rob.

Either:
(1) it needs to be "Save as PDF..." with the ellipsis, or
(2) Oops on my part.