Without using the mouse, how to trigger ‘Print’ in Gmail (using Google Chrome on the Mac)

chrome-extensionsgmailgoogle-chrome

Gmail has keyboard shortcuts for seemingly everything (including features I’ve never even used or heard of), but there appears to be no keyboard shortcut to print.

It also does not seem possible to make a custom keyboard shortcut to select “Print” either.

So far the closest that I’ve come is discovering that when a new message is loaded, I can press ⇧Tab twice to select the “Print” icon, and then press Enter to trigger it. But this completely fails if you have done almost anything after opening the message such as selecting some text, etc. So it is not reliable enough to be useful.

I’m hoping that someone either knows some JavaScript magic or perhaps there is a Google Chrome extension out there which might make this possible.

(After this many years of Gmail being around, I have to assume the lack of a keyboard shortcut for printing is intentional. Perhaps someone at Google thinks we ought to be living paperless lifestyles, or they figure if you keep all of your email in Gmail rather than printing them to PDF then you’ll use Gmail more. However, I suppose the ‘why’ really isn’t all that important, but it does seem like a strange oversight. At least to me.)


Update:

I guess I should have been explicitly stated that neither ⌘P nor File » Print will work.

That's why Gmail has its own print icon which opens the message in its own window. Otherwise Chrome tries to print out the sidebar and everything else around the message and you won't even see the main message as part of the printed page or PDF.

Best Answer

Here is one way that I triggered the Print sheet in Gmail within Google Chrome using a keyboard shortcut:

Doing this on macOS High Sierra1, in Automator, create a new Service.1

Set Service receives1 no input in Google Chrome

Add a Run AppleScript action, replacing the default code with the following example AppleScript code:

tell application "Google Chrome" to execute front window's active tab ¬
    javascript "document.getElementsByClassName('T-I J-J5-Ji T-I-JN L3')[2].click();"

Save the Service as, e.g.: Google Chrome Gmail Print

1 In macOS Mojave, and later, an Automator Service is called a Quick Action. There are also other minor nomenclature differences but they should be more obvious when comparing them to pre-macOS Mojave Automator workflows.

Automator Service

Assign the Service a keyboard shortcut in: System Preferences > Keyboard > Shortcuts > Services

I assigned ⌃⌘P to the e.g. Google Chrome Gmail Print Service.

Now in Gmail, within Google Chrome, having an email opened showing the print icon, as shown circled in red in the first image below, and I press ⌃⌘P the Gmail Print sheet, as shown in the second image below, is revealed.


Gmail - Opened Email

Note that in the standard view, as shown in the Gmail image above, there are four ElementsByClassName with T-I J-J5-Ji T-I-JN L3 as the class name. Index [0] and [1] are used by the Collapse all icon or Expand all icon that will show, when applicable, to the left of the Print all icon [2] and index [3] is used for the In new window icon to the right of the Print all icon.

Gmail Print sheet


Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors.