Non-Top-Posting Reply Scripts for Apple Mail (with Signature Support) ¬

2007-07-11

Today John Gruber posted an excellent set1 of AppleScripts that automate replying without top-posting in Apple’s Mail.app. You can read his article for the full description.

It’s exactly what I’ve been looking for to allow myself to keep my anal-retentive e-mail replying habits and increase productivity. However, I had one problem with his implementation: it doesn’t handle signatures gracefully.

I have a couple different e-mail accounts in Mail.app that I use on a daily basis and each has a unique signature (which also helps me know which account I’m replying from), but his script dumps you after the signature if you have one set to be auto-selected. I could just set it to select “None” by default, but then I lose the increased efficiency by having to select the signature.

So, I came up with a four-line addition to his script which adds the following fourth step to his process:

  • If no default or random signature is selected, select the first signature from the pop-up menu.

It is implemented by adding the following immediately before the second-to-last “end tell“:

if value of (pop up button 1 of window 1) is "None" then
	click pop up button 1 of window 1 -- The "Signature" Pop-up
	click menu item 3 of menu 1 of pop up button 1 of window 1 -- The first signature in the list
end if

Of course, one can always change “menu item 3“ to read “menu item ‘signature-name“, where “signature-name“ is the name of the signature you want to select, if you don’t want it to just pick the first out of the list. Hell, you can even modify it to pick a random signature if you want.

So, to be as clear as possible, the full, modifed, AppleScript is as follows:

tell application "Mail" to activate
tell application "System Events"
	tell process "Mail"
		tell menu bar 1
			click menu bar item "Message"'s menu "Message"'s menu item "Reply"
		end tell
		delay 0.5
		key code 117 -- Forward Delete
		key code 125 using command down -- Down Arrow
		key code 36 -- Return
		if value of (pop up button 1 of window 1) is "None" then
			click pop up button 1 of window 1 -- The "Signature" Pop-up
			click menu item 3 of menu 1 of pop up button 1 of window 1 -- The first signature in the list
		end if
	end tell
end tell

Thanks go out to John. Hopefully my modifications will be helpful to others too.

Update: My apologies for the horrendously tiny font for my code blocks. I’ve had a redesign in the works for a while. The site redesign has now gone live, so the code font should be much more legible.

1 I guess you’d call it a set. It’s one script with instructions for the one word addition to make the second script.

  1. Ha I was going to say! You removed it ;)

    “Message”‘s ¬(”)

    Cheers

  2. I would love to learn how to add a signature to mail.app accounts automagically depending on which account you are replying from!! i always have to select a signature

  3. @David Hall: Whoops, obviously I just copied & pasted that from Script Editor.app.

    @vanni: In Mail.app, go to Preferences and click the Signatures tab. You can then drag any signature from “All Signatures” (in the left-most column) to the specific account name (also in the left-most column) which you want that signature to be automatically associated with.

    Hope that answers your question.

  Textile Help