Saturday, January 22, 2011

Mac Outlook 2011: Keyboard shortcut to quickly file messages

Trying a switch to Outlook 2011 for Mac I needed a keyboard shortcut to quickly move selected email messages to specific folders. I edited some of the default AppleScripts which appear in Outlook's script menu, ended up with a script per folder I want to move messages to. Next step was to assign a keyboard shortcut to each script e.g. Option-A for File Message to Archive, Option-F for File Message to Follow-Up and so on.


A sample script is below, this is the one I use to move messages to a folder named "Archive", I simply created copies of this script for each folder I want to move messages to from the keyboard. The script is saved under ~/Documents/Microsoft User Data/Outlook Script Menu Items/File Message to Archive.scptd

*** UPDATE*** Microsoft released an Office 2011 SP2 upgrade on 4/12/2012, in this version of Outlook the scripts are expected to be placed in the folder: ~/Library/Application\ Support/Microsoft/Office/Outlook\ Script\ Menu\ Items/

The keyboard shortcut mapping is done from the OSX > System Preferences > Keyboard panel, just create a new Application shortcut, pick Outlook 2011 as the application and enter the exact name of your script as it appears in the script menu.


(*

 File message to Archive folder

*)

on run {}
 
 tell application "Microsoft Outlook"
  
  -- listSelectedItems : a list of all items selected in Entourage
  set listMessages to current messages
  
  -- Check to make sure items are selected, if not then quit
  if ((count of listMessages) < 1) then return
  
  -- Iterate through selected items
  repeat with objInSelection in listMessages
   
   set listFolders to mail folders
   
   repeat with objFolder in listFolders
    
    if (name of objFolder is "Archive") then
     set gtdFolder to objFolder
    end if
    
   end repeat
   
   if (class of account of objInSelection is not imap account) then
    -- IMAP currently not supported
    move objInSelection to gtdFolder
   end if
   
  end repeat
  
 end tell
 
end run

17 comments:

Jakibe said...

Thanks for posting this! I have been looking off and on for a couple of weeks for this exact script. I recently moved over from Outlook Windows where I had these types of Macros set up and I was missing them badly when I was processing email.

Thanks again for the work and for sharing!

Anonymous said...

I commented out your lines to exclude IMAP and it seems to work fine. Any gotchas I need to be aware of?

thanks for the script!

Sylvain said...

@Anonymous, there shouldn't be a problem, the exclude IMAP code is in all built-in scripts so I left it there b/c the IMAP folders behavior might be different.

I've been using the script on an Exchange BPOS connection for a few days and have no issue to report so far.

Sef said...

Thanks, this was helpful.

ALee said...

Amazingly helpful. Thanks for posting this up!

ALee said...

Amazingly helpful. Thanks!

John E. said...

Hi there - this is a wonderful post, thank you.

One thing that I noticed is that after initiating a new shortcut, like copying to my "XYZ" folder; if I failed to use the incorrect shortcut, and it copies to "ABC", when I Command+Z (undo), it doesn't undo the move. Any ideas on how to tweak the script?

Sylvain said...

Hi John - You're correct and unfortunately I do not know of a way to make the AppleScript actions "undoable". The same caveat exists on Windows with the Outlook macros that I provided in another post.

Steve s said...

For those new to apple scripts in general. The text above cannot be saved a .txt file, but must be saved as a script bundle. This can easily be done by using the "Script Editor" to save/edit the file. I used emacs...silly me.

Anonymous said...

does anyone else have a problem getting this script to work since updating to Office 14.2 (SP2)?

Anonymous said...

I'm just doing the SP2 upgrade now, will take a look and update accordingly.

Sylvain said...

Found the problem, after SP2 upgrade Outlook now expects the scripts to be in the path below. To make the macro work again just move your scripts from:

~/Documents/Microsoft\ User\ Data/Outlook\ Script\ Menu\ Items/

to:

~/Library/Application\ Support/Microsoft/Office/Outlook\ Script\ Menu\ Items/

Anonymous said...

I'm having a tough time getting the script to move the message to the appropriate folder. I have an Exchange account with a ""Filed" folder, a Gmail account with a "Filed" folder, and a couple local folders named "Filed" as well. The script is putting the selected message in the "On My Computer > Personal Archive > Filed" folder but instead I'd like it to move it to the "Inbox > Exchange > Filed" folder. How do I specify the correct folder in the script?

Anonymous said...

[Exhale], thank-you!

KW said...

Anonymous 2 posts ago,

I found another script with slightly different code that lets you specify which "filed" folder from which account you want. the code is:
set theAccount to account of theMsg
set archiveFolder to folder "Archives" of folder "Inbox" of theAccount

Ravi Venkatesan said...

The folder that worked for me is:
/Users/myname/Library/Application Support/Microsoft/Office

Anonymous said...

Solving @Anonymous's issue (and mine) from above, just change the conditional to this:
if ((name of objFolder is "Archive") and (name of account of objInSelection is name of account of objFolder)) then