Tuesday, September 09, 2014

Using gmail hotkeys in outlook

I am obsessed with saving keystrokes and despise having to use my mouse for ANYTHING.  (I could do the math for you on how saving 1-3 seconds per action multiplies by thousands and becomes savings of weeks or even months during a lifetime, but usually only geeks are interested so I'll refrain.)  So for me the hotkeys in gmail are fantastic.

My company has just moved to a new email protocol which requires me to move back to Outlook with an exchange-based email server for work-related stuff.  I really missed those gmail hotkeys (especially e to archive and go to the next message because I hate deleting messages!) and another colleague (thanks, Andreas!) pointed me to this article - full credit there for 90% of the work!

This only makes sense if you are connecting to your email server in Outlook 2013 via IMAP or Exchange so that the changes will be propogated.  Obvious, I suppose, but better to be clear.

It requires AutoHotKeys (AHK) but I already use that on a regular basis for all kinds of macros and hotkeys and other quickie-type programs. [What?! You don't use it?! How have you lived?!?!]

But the problem was that it was written for Outlook 2007 and 2003 whereas I have 2013.  Fortunately after a bit of banging around (and using the comment from the guys who previously converted it for version 2010) it was fairly straightforward to convert it for use in Outlook 2013.

(1) Install AHK, putting the AutoHotkey.ahk somewhere accessible and including a shortcut from your start menu. [1] Make sure it works by testing with the ctrl+alt+n hotkey to bring up notepad.
(2) In outlook create a folder (I called it "archived" under "inbox") and then make a QuickStep called "Move to Archived" to move the current email message into that folder and mark it as read.  In properties set it up to use CTRL-SHIFT-1 as the shortcut key.  Test it - pressing CTRL-SHIFT-1 should move the current message into the archive folder. Do the same with a second email account and appropriate archive folder, if applicable [2]
(3) Open the AutoHotkey.ahk file with your favorite TEXT editor (notepad works, vim is much better but requires a certain level of geekiness) and copy/paste the following into it at the very top:

SetTitleMatchMode, RegEx    ; This MUST be at the very top to auto-execute

; FROM http://www.ocellated.com/2009/03/18/pimping-microsoft-outlook/
; MODIFIED AND RE-POSTED FOR Outlook 2013: 
;*************************************************************************
;"GMAIL" Hotkeys for Outlook 2013
;*************************************************************************
;As best I can tell, the window text ‘NUIDocumentWindow’ is not present
;on any other items except the main window. Also, I look for the phrase
; ‘ – Microsoft Outlook’ in the title, which will not appear in the title (unless
;a user types this string into the subject of a message or task).

#IfWinActive,- Outlook,NUIDocumentWindow
;y::MsgBox Hello, World y
f::HandleOutlookKeys("^f", "f") ;forwards message
r::HandleOutlookKeys("^r", "r") ;replies to message
a::HandleOutlookKeys("^+r", "a") ;reply all
v::HandleOutlookKeys("^+v", "v") ;Move message box
+u::HandleOutlookKeys("^u", "+u") ;marks messages as unread
+i::HandleOutlookKeys("^q", "+i") ;marks messages as read (^q is read/unread toggle)
j::HandleOutlookKeys("{Down}", "j") ;move down in list
+j::HandleOutlookKeys("{Down}{Enter}", "+j") ;move down and select next item
k::HandleOutlookKeys("{Up}", "k") ;move up
+k::HandleOutlookKeys("{Up}{Enter}", "+k") ;move up and select next item
o::HandleOutlookKeys("^o", "o") ;open message
s::HandleOutlookKeys("{Insert}", "s") ;toggle flag (star)
c::HandleOutlookKeys("^n", "c") ;new message
/::HandleOutlookKeys("^e", "/") ;focus search box
.::HandleOutlookKeys("+{F10}", ".") ;Display context menu
#IfWinActive

#IfWinActive, Inbox - MYADDRESS@example.com - Outlook ahk_class rctrl_renwnd32,NUIDocumentWindow
e::HandleOutlookKeys("^+1", "e") ;calls archive macro

#IfWinActive, Inbox - MYADDRESS2@example.com - Outlook ahk_class rctrl_renwnd32,NUIDocumentWindow
e::HandleOutlookKeys("^+2", "e") ;calls archive macro

;Passes Outlook a special key combination for custom keystrokes or normal key value, depending on context
HandleOutlookKeys( specialKey, normalKey ) {
;Activates key only on main outlook window, not messages, tasks, contacts, etc.
IfWinActive, - Outlook ahk_class rctrl_renwnd32, NUIDocumentWindow, ,
{
;Find out which control in Outlook has focus
ControlGetFocus, currentCtrl
;MsgBox, Control with focus = %currentCtrl%
;set list of controls that should respond to specialKey. Controls are the list of emails and the main (and minor) controls of the reading pane, including controls when viewing certain attachments.
;Currently I handle archiving when viewing attachments of Word, Excel, Powerpoint, Text, jpgs, pdfs
;The control ‘RichEdit20WPT1' (email subject line) is used extensively for inline editing. Thus it had to be removed. If an email’s subject has focus, it won’t archive…
ctrlList = Acrobat Preview Window1,AfxWndW5,AfxWndW6,EXCEL71,MsoCommandBar1,OlkPicturePreviewer1,paneClassDC1,RichEdit20WPT2,RichEdit20WPT4,RichEdit20WPT5,RICHEDIT50W1,SUPERGRID1,SUPERGRID2,_WwG1,OutlookGrid1
if currentCtrl in %ctrlList%
{
Send %specialKey%
;Allow typing normalKey somewhere else in the main Outlook window. (Like the search field or the folder pane.)
} else {
Send %normalKey%
}
;Allow typing normalKey in another window type within Outlook, like a mail message, task, appointment, etc.
} else {
;this_id := WinExist("A")
;WinGetTitle, this_title, ahk_id %this_id%
;MsgBox DEBUG: Non-active (%A_TitleMatchMode%) :%this_title%:
Send %normalKey%
}
}
; END FROM http://www.ocellated.com/2009/03/18/pimping-microsoft-outlook/


(4) Edit that text, replacing MYADDRESS@example.com and MYADDRESS2@example.com with your email address [2]
(5) Right-click on the hotkey icon in the notification area (green box with white H) and click on "Reload this script".

Voila - feel free to use r to reply, f to forward, e to archive, s to star, j to move down, k to move up, etc.

If you have any problems, please let me know in the comments.

If it works at first but stops working after you reboot then you need to look at your AHK installation and make sure you've got the scheduler set up correctly.

If you're wanting to use this on a Mac ... [maniacal laughter fades into the distance]




[1] Getting something to start automatically in Windows 8 or 8.1 is a bit of a pain in the neck.  I think I ended up using the windows scheduler as per this article, but I did it quite some time ago (when I first installed win8) so I don't remember exactly.  [I do wish AHK would give an option in their installer to do that automatically!]

[2] I have set this up so with 2 separate addresses because I use my corporate address as well as my gmail address in Outlook via IMAP. I obviously don't want to archive my corporate email into my gmail "all mail" nor do I want to archive my personal email into my corporate archive. So that's why I've got it separated. If you are only using a single IMAP account then you wouldn't need to do anything with the 2nd QuickStep or to mess with changing the MYADDRESS2@example.com to your address.

0 Comments:

Post a Comment

<< Home