Create a gist now

Instantly share code, notes, and snippets.

@gruber /Reply.scpt
Last active Sep 24, 2015

Prompt with options to "Reply" or "Reply All" when replying to a message with multiple recipients in Apple Mail for Mac OS X. Also does away with top-posting.
tell application "Mail"
set _sel to get selection
if (count of _sel) > 1 then
-- multiple message selection, usually a conversation thread
choose from list {"Reply", "Reply All"} with prompt "Unknown recipient count." default items {"Reply"}
try
set _menu_command to item 1 of the result
on error
return
end try
else
set _msg to item 1 of _sel
set _count to count recipients of _msg
if (_count > 1) then
choose from list {"Reply", "Reply All"} with prompt (_count as string) & " recipients:" as string default items {"Reply"}
try
set _menu_command to item 1 of the result
on error
return
end try
else
set _menu_command to "Reply" -- Default for messages with single recipient
end if
end if
end tell
tell application "System Events"
tell process "Mail"
delay 0.5
tell menu bar 1
click menu bar item "Message"'s menu "Message"'s ¬
menu item _menu_command
end tell
-- Delete or comment out the `delay` and `key code` lines below if
-- you prefer Mail's default top-posting behavior.
delay 0.25
key code 117 -- Forward Delete to nuke top blank line
-- Fix trailing whitespace
key code 125 using command down -- move to bottom
key code 123 using option down -- Option-LeftArrow
key code 124 using command down -- Cmd-RightArrow
key code 117 using option down -- Option-ForwardDelete
key code 36 -- Return
key code 36
end tell
end tell
@gruber
Owner

Took out the bit where it didn't run if multiple messages were selected; that conflicted with Lion Mail's conversation view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment