Macro to print a gmail message to PDF and file (in Google Drive or Dropbox)

Hey all: A bit of a noob here on KM.

I've been banging me head on the wall for a couple of hours trying to find a way to automate the following from the web version of gmail.

  1. Print the message to PDF
  2. File it in a folder for us with Hazel
  3. Archive or delete the message

There doesn't seem to be a non-mouse way of printing a message in Gmail without clicking the print icon.

Has anyone seen a solution to this?

Thank you in advance.

Gmail has keyboard shortcuts for features I've never even heard of but they don't have one for "Print".

This is what happens when you live in a tech bubble instead of the real world. I'm guessing someone decreed that "We [at Google] don't want to make printing easy because blah blah paperless lifestyle."

I googled around and did not find any way to assign a keyboard shortcut to it.

It's possible one of the JavaScript gurus might find a way to target the print button using JS, but unfortunately I do not know how to do that.

(The print icon is set as 'tabindex=0' which means -- as far as I can tell -- that it is supposed to be the default navigation item when pressing 'tab' but that does not seem to be the case at all. I don't know if there is a way to trigger it by 'tabindex' either… tabindex seems like one of those good ideas that doesn't seem to work as expected, or be well-supported.)

I do have a workaround… but I don't think it's probably one that you want… use Mailplane. Its "Print" function seems to replicate pressing the "Print" icon, and brings up the regular macOS print dialogue window. This should mean that you could control the whole thing via Keyboard Maestro. Depending on how badly you want to do this, it might as least be worth checking out the demo of Mailplane? I've used it for years and consider it to be top-notch, and my favorite way to use Gmail on the Mac.

(Since someone might ask or wonder: Kiwi for Gmail just seems to print the entire browser window, which isn't what anyone wants.)

Thanks for that....

I played with hitting "shift-tab" twice and that got me to highlight the print icon where I could press print via the enter key, but I was not able to get KM to accomplish the SHIFT-TAB. Would prefer not to use Mailplance since I have some extensions that are not supported.

I assume you tried "Type A Keystroke" and then just did "⇧Tab"? What happened instead?

Do I take this to mean that you are using Google Chrome to read Gmail? Just wondering if maybe someone out there has a Chrome-specific way to solve this.

Yes, that is my fault for not being more clear on my set up ---- chrome 99% of the time.

This is what I came up with, which seems to work but you must not have selected anything else after opening the message. But if you just navigated there using J or K then this should work:

Of course that is in a Macro Group which is only active for Google Chrome. You might need to make one of those if you don't already have one.

Here's the macro:

Chrome - Gmail - Print All.kmmacros (24.2 KB)

Note that I tend to use a lot of 'pause' statements when creating something like this. You might be able to get away with shorter ones, but in the "development" stage, I find them helpful.

The last one is definitely necessary, as it takes a few seconds for Chrome to render its fake print dialogue box. Once that is there, you can use ⌥⌘P to bring up the regular print dialogue box. From there you can use the ⌘P to Print as PDF "trick" if you have that enabled. You'd probably still need to intervene to name the PDF and maybe even choose a folder to save it to.

But maybe this will get you started?

Let me know.


p.s. I found this question interesting enough that I also posted it on Ask Different. Maybe someone there will have an idea, too.

So strange, for me, KM will not emulate the shift-Tab. I can do it manually but KM doesn't do anything. I used debug and it recognizes that it is chrome and walks through it. That was really cool of you to post on Stack Exchange, btw. Thanks man.

That's an odd one. Maybe @peternlewis needs to take a look at it to offer an explanation.

The only thing I can think of… and it it works outside of Keyboard Maestro then this probably isn't it… but do you have this set to "All Controls"?

For some reason Apple keeps the default "Text boxes and lists only" which I find weird. And it may be completely unrelated. It's just the only thing I can think of as to maybe possibly why Keyboard Maestro wouldn't be able to emulate that?

(Now that I think about it, my idea doesn't make much sense, but maybe Peter will have an idea.)

That didn't help, but I owe you a HUGE thanks for helping me tonight. I'll wait for Peter. Thanks so much - Ryan

Maybe this? I haven't tried it but found it while Googling around.

Here is another option that just worked for me.

https://wiki.keyboardmaestro.com/action/Move_or_Click_Mouse

I had KM look for the printer image on my screen and then click it.

FYI, if you read gmail sometimes on an ios device, you can share the message to Print and then pinch zoom in on the preview. At this point you can share the message to an app as a pdf. I use this to send pdfs to DEVONthink, but you could use it to send to Dropbox, Box, etc.

1 Like

Mark

Do you mind sharing the macro. I got it to find the image (it highlighted it) but the click did nothing.