Make Gmail delete the current message and open the next one

Gmail is great and their keyboard shortcuts help out quite a bit, but it was missing the ability to delete the current message and move to the next message in any folder or list of messages. After discovering AutoHotKey (AHK) to build and customize shortcuts for applications, I decided to solve this problem I’ve been dealing with for some time.

I did find some pages online where people were asking how to make this work or why Gmail doesn’t offer this feature. So I looked at the Keyboard Shortcuts in the Gmail Lab for a solution, but you can only do one command at a time there. So the key sequence is #o (pound sign and then the letter “o”) to move the current message to the trash and then open the next message.

Sidenote: Even if I wanted to use the delete key and then the letter “o”, I couldn’t put in \127 for the ascii code for Delete in the Keyboard Shortcuts Lab feature. It seems that the textbox only allows 3 characters.

So I cooked up this solution to make the delete key do it all – #o.

First, you need AutoHotKey installed. Then you need to create a new AutoHotKey file or just edit the AutoHotkey.ahk that gets installed by default. You can have multiple AHK files loaded at the same time if you want. I just keep using the same one for all my shortcuts.

Edit the AHK file with notepad or your favorite text editor and copy/paste the following lines. I prefer to use Notepad++ but it really doesn’t matter.

SetTitleMatchMode 1
#IfWinActive Gmail -
Delete::
; Delete the current message and
Send #
;read the next message
Send o
return
#IfWinActive

Double-click on your newly edited and saved AHK file. This will load it and you will see AHK running in the system tray as a green square with an “H”.

image

Now open Gmail and go to your inbox or spam folder where you have messages you want to delete. Then click on the first one to read it and hit the delete key.

In order for this to work after you reboot your computer, you need to add a shortcut to this AHK file to your startup folder so it loads automatically after a reboot.

 

There are a couple of things that could go wrong where this solution will not work:

  • If you changed the Keyboard Shortcut in Gmail for Open conversation from a “o” to something else or you changed the Move to trash from “#” to something else, you need to change the AHK file to match. Look at the lines that start with Send in the AHK file and change the characters as needed, save the file, right-click on image in the system tray so you can click on Reload This Script. Then see if the delete key works like you want it to.
  • If you enable the Title Tweaks in Gmail Lab to show the folder name followed by “- Gmail” in the title of the browser, you will need to change line 2 in the AHK file to
#IfWinActive - Gmail

 

Here are some notes about the AHK commands used here:

  • Since AHK can map keys in any application I needed to specify the title or window name of the application and SetTitleMatchMode 1 describes how AHK will look for the title. From the AutoHotKey documentation: A window’s title must start with the specified WinTitle to be a match
  • To make AHK only take over keys in a particular application, use IfWinActive see the AutoHotKey documentation for more details.

Comments are closed.