Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Archive messages in Mail.app using a single keystroke Apps
Here's an AppleScript to archive messages in Mail.app using a single keystroke.

Unlike related hints, this script is designed to be launched with a single keystroke using a tool like FastScripts.

The basic logic flow: if a mailbox view is in the foreground, it will archive the selection; if not, it will skip archiving and (optionally) enter the keystroke you typed in the first place.

Steps:

  • Download this script and a tool like Fastscripts
  • Move the script to ~/Library/Scripts/Applications/Mail/.
  • Set your hotkey in Fastscripts or your script launcher of choice. (Using a letter key is possible but not recommended. Try another character like `\/=- or an F-Key.)
More info is available here in my blog about it.

Here's the script:
(*
  # DESCRIPTION #
  
  This script files the selected Mail messages to the specified folder (Archive, by default).
  
  
  # LICENSE #

  Created by Dan Byler (contact: dbyler@gmail.com); released as public domain.
  
  
  # CHANGE HISTORY #
  
  0.1: Original release.

  
  # INSTALLATION #
  
  -  Copy to ~/Library/Scripts/Applications/Mail
   -  If desired, activate with Fastscripts
*)


--name of the mailbox you're filing to
property fileMailbox : "Archive"

--if composing a message, paste the character you typed?
property doPasteText : true
property escText : "\\" --if using backslash, remember to escape it

tell application "Mail"
  repeat with thisMessageViewer in message viewers
    
    -- Is the message viewer in front? Avoid accidentally triggering
    if window of thisMessageViewer is first window then
      
      set theSelectedMessages to selection --todo just use "selection"
      if theSelectedMessages is {} then
        return
      end if
      
      set visibleMessages to visible messages of thisMessageViewer
      set firstID to id of first item of theSelectedMessages
      set lastID to id of last item of theSelectedMessages
      
      -- Change selection
      
      repeat with i from 1 to (count visibleMessages)
        if id of item i of visibleMessages is firstID then
          try
            -- Make sure we're navigating to a valid message
            if class of item (i - 1) of visibleMessages is message then
              set thisMessageViewer's selected messages to {item (i - 1) of visibleMessages}
            else -- If not, it's probably a message thread; skip back another
              set thisMessageViewer's selected messages to {item (i - 2) of visibleMessages}
            end if
          on error --likely at top of viewer
            try
              set thisMessageViewer's selected messages to {item (i + 1) of visibleMessages}
            end try
          end try
        else if id of item i of visibleMessages is lastID then
          try
            set thisMessageViewer's selected messages to {item (i + 1) of visibleMessages}
            exit repeat
          end try
        end if
      end repeat
      
      -- Move messages
      repeat with theMessage in theSelectedMessages
        set theAccount to name of account of mailbox of theMessage
        move theMessage to mailbox fileMailbox of account theAccount
      end repeat
      
      return
    else
      if doPasteText is true then
        -- Let the original keystroke pass through.
        -- Uses paste to avoid an infinite script-triggering loop.
        tell application "System Events"
          set currentClipboard to the clipboard
          set the clipboard to escText
          keystroke "v" using {command down}
          delay 1
          set the clipboard to currentClipboard
        end tell
      end if
    end if
  end repeat
end tell

[crarko adds: I haven't tested this one. You should be able to bind this to a keyboard shortcut in Mail using the Keyboard Shortcuts System Preference.]
    •    
  • Currently 2.33 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[3,773 views]  

Archive messages in Mail.app using a single keystroke | 4 comments | Create New Account
Click here to return to the 'Archive messages in Mail.app using a single keystroke' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Archive messages in Mail.app using a single keystroke
Authored by: interlard on Mar 24, '11 11:21:31AM

My delete key already archives messages in Gmail.



[ Reply to This | # ]
Archive messages in Mail.app using a single keystroke
Authored by: RMo on Mar 25, '11 10:59:34AM

Exactly. Since they say "archive," I can only assume they're referring to Gmail. This kind of hackery has not been necessary in IMAP clients with Gmail for years. (Or maybe it's always been that way--I can't remember.)

Can people please stop sharing these "hints," unless there's some value to them that I don't see?



[ Reply to This | # ]
Archive messages in Mail.app using a single keystroke
Authored by: babaloo on Mar 25, '11 12:09:42PM
Since they say "archive," I can only assume they're referring to Gmail.
I don’t think so. I rather think, "archive" here is used as a generic term. Besides Gmail I personally use different accounts from different providers. And I use a single archive folder. But that does not sit in Gmail.
So in fact this hint is useful, whether or not you are using Gmail.

[ Reply to This | # ]
Archive messages in Mail.app using a single keystroke
Authored by: adiascar on Mar 24, '11 12:49:56PM

I use Archive for the same functionality:
http://stl.techinno.nl/archive/



[ Reply to This | # ]