Gmail - Compose Macro

When composing Gmail …

  • I want to have a UNIQUE compose window open up
  • I want it to be placed in the proper location and size on the main screen.

The following macro serves to meet the above stated interests.

Compose message in Gmail.kmmacros (4.9 KB)

1 Like

Hey There,

I'd do the heavy lifting more directly with the shell or with AppleScript.

###AppleScript:

set gmailURL to "https://mail.google.com/mail/u/0/?ui=2&view=cm&fs=1&tf=1&shva=1"

tell application "Google Chrome"
  activate
  set newWin to make new window with properties {bounds:{0, 22, 1040, 1196}}
  tell newWin
    set URL of active tab to gmailURL
  end tell
end tell

The shell script will be a little more bombproof; the AppleScript a little more versatile.

The AppleScript might time-out if Chrome took a long time to launch, but that can be worked around in the script of course.

-Chris

Thanks Chris,

I have some programming experience, but really not a whole lot. I come more from a background of an electrical and systems engineer. But I certainly aspire to the idea that implementing a solid, foolproof solution.

But the fact I could whip together the script to do exactly what I wanted (albeit, perhaps slower, more prone to race conditions, “not commercial ready") underscores the beauty of Keyboard Maestro.

My current script makes composing a fast email 100x better than the old way of opening Gmail: clicking compose; getting a little window; needing to reposition; etc. I almost enjoy the fact that it takes 6 seconds to open the window because I get to watch KM elegantly dance around Google’s Gmail dysfunction, with all the effort required to bring that compose window up exactly where I want it.

I think what I find most impressive is that KM provides so many potential solution angles for all those essential applications that I have used over the years, day in and day out - applications where I have gone onto forums desperate to get the author to make some minor change that would make my daily life 100% easier, only to have the requests ignored because they were swamped swamped or the request “not mainstream enough”. But now, none of that matters anymore. Using KM, I can fix it myself.

Anyway, as for a tighter script to get my compose window going, I’ll give that shell script and AppleScript a shot, Better is always… better, but at least I’m not desperate for a fix.

Hey Ed,

Yes. It’s very satisfying to get things on a computer (especially a Mac) to work the way you want them to. I found the original 128K Mac to be about as useful as a balsa wood boat anchor, until we turned it into a MacPlus, I acquired a ramdisk utility, I got a DataDesk 101 keyboard, and I installed QuicKeys v1.0.

Since then I’ve tried or owned virtually every usability utility that’s come out for the Mac.

Keyboard Maestro is the current the best-of-breed automation utility for the platform, and it makes computing-life easier and more productive for users every day.

-Chris

1 Like

Hey Folks,

This updated AppleScript will reveal the Gmail tab in Chrome if it is already open and then open a compose panel – otherwise a new window with a Gmail compose panel will be opened.

-Chris

---------------------------------------------------------------------------------
# Auth: Christopher Stone <scriptmeister@thestoneforge.com>
# dCre: 2015/05/14 12:30
# dMod: 2016/06/01 17:23
# Appl: Google Chrome
# Task: Bring Chrome Tab with Gmail to front if it exists - otherwise open Gmail in new window a.
#     : Then open a compose panel.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Google_Chrome, @System_Events, @Gmail, @Compose
---------------------------------------------------------------------------------
set gmailComposeURL to "https://mail.google.com/mail/u/0/#inbox?compose=new"
set gmailInboxURL to "https://mail.google.com/mail/u/0/?tab=wm#inbox"
set _win to false

tell application "Google Chrome"
  set {idList, urlList} to {id, URL} of every tab of every window
end tell

set AppleScript's text item delimiters to linefeed

if (urlList as text) contains "https://mail.google.com/mail/" = true then
  set theWin to 1
  repeat with urlSubList in urlList
    set theTab to 1
    repeat with theURL in urlSubList
      if theURL starts with "https://mail.google.com/mail/" then
        set {_win, _tab} to {theWin, theTab}
      end if
      set theTab to theTab + 1
    end repeat
    set theWin to theWin + 1
  end repeat
end if

if _win ≠ false then
  tell application "System Events"
    if quit delay ≠ 0 then set quit delay to 0
    tell process "Google Chrome"
      perform action "AXRaise" of window _win
    end tell
  end tell
  tell application "Google Chrome"
    tell front window
      set active tab index to _tab
      set URL of active tab to gmailComposeURL
    end tell
  end tell
else
  tell application "Google Chrome"
    set newWin to make new window
    tell newWin to set URL of active tab to gmailComposeURL
  end tell
end if

---------------------------------------------------------------------------------
2 Likes