Create an email in gmail, then include subject line and body text?

Hi there. New user of KM here, and love it so far.

I want to set a macro that creates a new email in my gmail web interface (chrome browser in catalina btw), then inserts a specified subject line and body text.

I searched for a while in here and i found this great "# Task: Bring Chrome Tab with Gmail to front if it exists - otherwise open Gmail in new window a. # : Then open a compose panel." script from @ccstone (thank you, chris) it only goes as far as opening a blank compose window.

Is what I want to do even possible?

Many thanks in advance!!

Assuming you have gotten to the point where the Compose button has been pressed, then (possibly after a short Pause), you should be able to simply do:

  • Type a Key Stroke Tab
  • Insert Text by Typing "Subject Line"
  • Type a Key Stroke Shift-Tab

Wouldn't that work?

hey peter, thanks for replying.
It seems that when executing an applescript the option to tag on following actions is removed.

Or am I using that script wrongly?

Do you mean there is no New Action button under the action?

image

If so, no, that's a bug, it should always be there. Could be some sort of visual glitch, but I have no idea how to cause it or repeat it.

I suggest you switch to another macro and back, or turn Edit mode off and on again to resolve the issue.

If you find out what you did that results in the New Action button disappearing, that would be helpful to know.

Oh my god, thank you so much. yes it seems to be a bug of some kind. There was no 'New Action' button after the script window, but shutting KM down and restarting it fixed that and now it works!!! Can't believe i didn't try turning it off and on again myself.. really should have learned by now.

If anyone else stumbles across this, I now have it working and I'm attaching the macro here for you to edit and use.

  1. Uses @ccstone script to detect whether gmail is open or not, and to open a new compose tab
  2. Pauses for 1 second
  3. Tab to subect line
  4. Pauses for 1 second
  5. Inserts your defined subject line
  6. Pauses for 1 second
  7. Tab to email body
  8. Pauses for 1 second
  9. Inserts your defined email body text

I tinkered around with the pause intervals but found if they are too short the commands run into each other and you end up with stuff like the body text being pasted into the subject line etc, but 1 second intervals seem to work just fine.

Gmail Compose Script.kmmacros (6.1 KB)

1 Like

You really should never have to.

If you get this happening again, and most especially if you can figure out duplicating it, please let me know.

For a normal Mac app, sequences of typing should not generally need pauses. However when changing focus (application, windows, etc), that's where Pauses are typically needed.

But web apps, that's a whole different kettle of fish, even straight typing in to a field can result in out of order characters if the app behaves poorly.

thanks peter, i will do.

actually i can replicate it. maybe it's something i'm doing wrong?
When I create a new test macro and choose 'Execute AppleScript', then paste in the script.. there's no option following that to add a new action. See here for an example I made 2 mins ago.

Sorry, my mistake, it goes away when you select Show Actions - just double click (or drag) any action in the action selector.

Basically, you click on that button, the Action Selector appears and you can add actions that way.

I forgot because I usually use the Insert Action by Name (⌘⌃A) to insert actions!

Also, you need to resolve this:

image

Click on the Triangle, and resolve the issue, otherwise you will have other problems.

aha thanks, that works!

Here'a script I use u=in Gmail for repetitive 'release' emails on a project. '
I manually open the blank email and make sure the cursor in in the "to" field.

  • it firsts puts three email addresses into the "to" field
  • shift-command-C then moves the cursor to the "CC:" field (a gmail keystroke)
  • it then enters two more email addresses into CC field
  • it then tabs into the subject field and enters my text
  • it then tabs into the body of the email to enter some boilerplate text.

I like to hear a pop after each entry. Also have some pauses included from having written this about a decade ago. Might still need them when gmail is on a slow connection. Perhaps not.

1 Like

I have a number of macros that create Gmail emails from URLs. The basic format is:

https://mail.google.com/mail/u/[MY-EMAIL-ADDRESS]/?view=cm&fs=1&to=[ADDRESS]&cc=[ADDRESS]&su=[PERCENT-FORMATTED-SUBJECT-TEXT]&body=[PERCENT-FORMATTED-BODY-TEXT]

Just run the subject and body through the Filter Text With Percent Encode for URL before constructing the URL, then open in your browser. Much more reliable (and faster) than pausing and tabbing and pasting.

1 Like

Aha! Thank you - clicking "CC:" via XPath wasn't reliable as it seems to change.

And even more Gmail functionality I was unaware of. That's really convenient. Time to upgrade my macro, thanks :slightly_smiling_face:

1 Like

The Gmail compose URL method has been great this past week. They offer a few more esoteric formats too but I've only needed the one you shared, Gabriel. For my setup, it's faster than macro'ing a native Mail.app compose.

I run this macro, copy an email and a name, and Gmail compose opens. Some plain text prefills, below which I paste a rich text signature.

(yeah a little embarrassing, high time to learn subroutines... and a mail service's API...)

Anyway, I wouldn't mind if Gmail gave a little more confirmation the email was sent, but that's always macroable :wink:

Another "thanks again" to durdles - super useful having a CC: prefill on my (one, overburdened) Conflict Palette.