How Do I Download (Print Web Page to PDF) and Email PDF?

I have been working on creating a workflow using Keyboard Maestro, Hazel and Automator and have gotten stuck.
Here's the workflow:
Sign onto a website using chrome at a set time each day
Use Command P to open the print dialog
Click the save button which in turn opens a finder window where a click on Save, saves a copy to my downloads folder. From there Hazel takes over and moves the file to a different folder, attaches the pdf to an email with a pre populated email address and subject line. Once the file is in the download folder, the part that Hazel and Automator does is working well.

Here’s what works:

  1. I can get KM to trigger at a set time each day
  2. Open the desired webpage in Chrome
  3. Open the print dialog and
  4. Click the save as pdf button that opens the Save dialog window to save the pdf in my downloads folder.

It is the last step in the macro, activating that Save dialog window and activating (clicking) the return to save the file to the downloads folder.
I have tried working with different pause times and even though this shouldn’t work, I tried adding the type return a second time. This got the macro to work a couple of times but not consistently.
This is my first time using KM and my first attempt at creating a macro. I’ve looked every where for an answer and after 8 hours I finally decided this is beyond my pay grade at this time. I’d greatly appreciate any help. Thanks in advance.

Keyboard Maestro “Email Data Studio Adwords Report to RVNA” Macro

Email Data Studio Adwords Report to RVNA.kmmacros (4.1 KB)

Hard for me to test what you have since I don’t use Chrome, but try replacing some of the Type The Return Keystroke actions with the Press A Button action (you’ll specify the name of the button you’d like clicked).

Delete all the Set Simulate Normal Keystroke actions. They are not appropriate for this purpose - they are for cases where you are typing a sequence of characters in an Insert Text by Typing action. And in any event, a Command key is not a “Normal” character. Just use Pause actions as necessary.

After Command-P, a Pause long enough for the Chrome Print dialog to appear is necessary.

I don’t know what the latter half of your macro is trying to do.

After the macro fails to print, if you press Return, does it print?

Hi Peter,
Thanks for your input. To answer your last question "After the macro fails to print, if you press Return, does it print?"
The answer is yes, instead of printing, in my case pressing return is supposed to save a pdf to my downloads folder. What happens is that everything works until the Save dialog box opens. It is at that point, the Save dialog needs to be active and the "Save" button needs to be clicked on or alternatively hitting the Return key on the keyboard will cause the pdf to save. When the macro runs, everything works until this point. If I manually hit the return key on the keyboard, the pdf does download to my designated folder (the download folder). After hat point Hazel and automator take over and the rest of the workflow runs fine.
Jonathan

Welcome! Definitely stick with the KM as it’s a game changer.

I’ve made a few macros that print/save to PDF.

When troubleshooting I usually go through trying things like this (in addition to what’s been mentioned already):

  • Waiting until an image unique to that screen is available before you hit Return (‘Pause Until’ Action > New Condition > Found Image Condition)
  • Alternative methods of pressing ‘Save’ instead of the Return key. Namely, the ‘Click at Found Image’, and ‘Press a Button’ actions.

If you’re still having trouble, then I recommend making a video with Quicktime Player (File > New Screen Recording) so we can see it fail.

You might take a look at these macros and posts for some good examples of printing a web page as a PDF:

It sounds very much to me like there simply isn’t a long enough pause before the Return key is simulated in the macro.

Add a 5 second Pause before the Simulate Return Key action at the end.

If that still fails, make a macro:

Hot Key “x” (any key you don’t use during the test will do)
Type a Keystroke: Return

Then instead of testing that you can press Return, try pressing “x”.

If that works, then the issue is with your macro (probably your timing, maybe your actions). If not (which would be very unlikely in this sort of case), that indicates the application is simply not listing to simulated keys (this would typically only be the case in things like Games or Cross Platform apps that are doing some low level stuff, highly unlikely in a dialog).

Problem solved. Thank you all for your support. After replacing "Set Simulate Normal Keystroke for This Macro" to "Pause", the final piece was to set the last pause for .5 seconds. Making it shorter rather than longer did the trick. I'm new to this forum. Is it a standard practice to upload to the Macro area for others to see/use? Thanks again for everyone's help. Here an image of the final working macro:
(url covered to protect client privacy)

Yes. It greatly helps us help you if you will upload both the file and the image of your macro when having issues/questions.

See