Opening the Gmail web interface with keyboard shortcuts

Problem: When I’m not in the browser it takes way too many clicks to get to Gmail, my email client of choice. First activate the browser, then find the Gmail tab (which is often tedious) before finally getting to Gmail. It’s worse if I also want to compose an email. For such a common action this is too complicated.

Solution: I wrote an applescript (triggered with Keyboard Maestro), that directly takes me to the Gmail interface, always in the first tab of the browser. I can also directly go to “compose”, or other often used views in Gmail with a keyboard shortcut.

Here is the applescript:


set theGmailLink to "https://mail.google.com/mail/u/0/#inbox"
tell application "Google Chrome"
  activate
  set allWindows to every window

  repeat with eachWindow in allWindows
    set allTabs to tabs of eachWindow
    set i to 0

    repeat with eachTab in allTabs
      set theURL to get URL of eachTab
      set i to i + 1

      if theURL contains "mail.google.com" then
        #I like to keep my windows this size but it can be commented out
        set the bounds of the eachWindow to {0, 0, 1275, 1800}

        set index of eachWindow to 1
        if theURL is not equal to theGmailLink then
          set URL of eachTab to theGmailLink
        end if

        #focus on the gmail tab
        set (active tab index of eachWindow) to i
        return #exit the script if a gmail tab was open already
      end if
    end repeat
  end repeat

  #this gets executed if no gmail tab was open
  set newTab to make new tab at beginning of tabs of front window
  set URL of newTab to theGmailLink

  #I like to keep my windows this size but it can be commented out
  set the bounds of the front window to {0, 0, 1275, 1800}
end tell

Instead of using a link to the inbox for theGmailLink, you can take any other gmail link from the address bar, like compose ("https://mail.google.com/mail/u/0/#inbox?compose=new"). Now the only thing left is to put it into a simple Keyboard Maestro action:

gmail - open inbox

 

Now getting to Gmail quickly is super easy, just a keyboard shortcut away.

Advertisements

3 thoughts on “Opening the Gmail web interface with keyboard shortcuts

  1. Hi, I solved it with this apple script:

    set x to 0
    tell application “Google Chrome”
    set allWindows to every window
    activate

    repeat with eachWindow in allWindows
    set x to x + 1
    set allTabs to tabs of eachWindow
    set i to 0

    repeat with eachTab in allTabs
    set theURL to get URL of eachTab
    set i to i + 1

    if theURL contains “mail.google.com” then
    set (active tab index of eachWindow) to i
    tell application “System Events” to tell process “Google Chrome”
    perform action “AXRaise” of window x
    end tell
    return #exit the script if a gmail tab was open already
    end if
    end repeat
    end repeat

    #this gets executed if no gmail tab was open
    set newTab to make new tab at beginning of tabs of front window
    set theGmailLink to “https://mail.google.com/mail/u/0/#inbox”
    set URL of newTab to theGmailLink
    end tell

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s