A while back, John Gruber posted a FastScripts script to fix a loathsome Apple Mail behavior, which was shortly followed by signature-enabled improvements. Fourteen short weeks later, here’s my own version:

tell application "Mail" to activate
tell application "System Events"
	tell process "Mail"
		-- Run the regular "Reply" command
		tell menu bar 1
			click menu bar item "Message"'s menu "Message"'s menu item "Reply"
		end tell
		delay 1.0 -- Give it a chance to finish
 
		-- Remember what signature was selected and switch to "None"
		set blib to value of (pop up button 1 of window 1)
		if blib is not "None" then
			click pop up button 1 of window 1 -- The Signature popup
			click menu item "None" of menu 1 of pop up button 1 of window 1
			delay 0.2
		end if
 
		-- Delete the return Mail inserted; recreate it at the bottom where it belongs
		key code 117 -- Forward delete
		key code 125 using command down -- Command-down (skip to the end)
		key code 36 -- Return
 
		-- Restore the previously selected Signature
		if blib is not "None" then
			click pop up button 1 of window 1 -- Still the Signature popup
			click menu item blib of menu 1 of pop up button 1 of window 1
			delay 0.2
			key code 117 -- Mail inserts a bonus line here too
		end if
	end tell
end tell

One drawback that I maintain from John’s original is the use of a time delay — I have other scripts that use them, and for each of them I occasionally have the script fail because my machine is a little busier that day.1 That being said, this script usually runs correctly.

My improvement is how I deal with arbitrary signatures. If you pick a different signature (or no signature) from the popup menu in the compose window, Mail updates the message correctly — so I just use that behavior to do the messy bits.

  1. Yes I’m still using a PowerBook — what’s that got to do with anything? []

AppleScript | Tagged , , | Permalink