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


Click here to return to the 'Change Mail behavior when replying to a message in the Sent mailbox' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Change Mail behavior when replying to a message in the Sent mailbox
Authored by: ccstone on Jun 15, '11 02:58:17AM
Others have covered the features of Mail (and plugins) that make this script's utility questionable, so I'll confine my comments to the Applescript code.

Original: set theMessages to the selected messages of the front message viewer

This line is very problematic, because it will not work if there is more than one message viewer open, and the front MV is not the first one opened.

This will fix that: set theMessages to the selected messages of some message viewer whose index is 1

Let us also please have at least basic error-checking:

try
  # Script Body
on error errMsg number errNum
  set sep to "=============================="
  set e to sep & return & "Error: " & errMsg & return & sep & return 
    & "Error Number: " & errNum & return & sep
  beep
  display dialog e
end try

Setting aside the merits of the script, let's rewrite it in more sturdy fashion just for the exercise:

tell application "Mail"
  try
    set quoteOriginalMessagePref to quote original message
    set selectedMsg to (get selected messages of some message viewer whose index is 1)'s 1st item
    if selectedMsg's mailbox's name = "Sent Messages" then
      tell selectedMsg
        set recipientList to {name, address} of its recipients
        set newOutgoingMessage to reply with opening window
      end tell
      delay 0.05 # This value might need adusting to allow the quoted material to show up.
      if quoteOriginalMessagePref = true then set quote original message to false
      tell newOutgoingMessage
        set address of to recipients to ""
        repeat with ndx from 1 to length of (item 1 of recipientList)
          make new recipient at end of to recipients with properties 
            {name:item ndx of item 1 of recipientList, address:item ndx of item 2 of recipientList}
        end repeat
      end tell
      if quoteOriginalMessagePref then set quote original message to true
    else
      error "Selected Messages Not in 'Sent Messages' Mailbox"
    end if
  on error errMsg number errNum
    try
      set quote original message to quoteOriginalMessagePref
    end try
    set sep to "=============================="
    set e to sep & return & "Error: " & errMsg & return & sep & return 
      & "Error Number: " & errNum & return & sep
    beep
    display dialog e
  end try
end tell

Kudos to the O.P. for figuring a way around Mail's evil multiple-quotation bug.

I prefer to run this sort of thing with FastScripts (a recent MacGem), because it handles app-specific keyboard shortcuts better than Mac OS X's service menu and has other useful features.

-ccs

Edited on Jun 15, '11 03:05:43AM by ccstone


[ Reply to This | # ]