Create new Mail signature

I frequently change my email signatures, adding new ones when I find something humorous or pithy or removing old ones when I tire of them. No surprise, then that I tossed together a quick script to let me copy text to the clipboard and make it into a new Mail signature.

The hardest part was getting it to be a generic script, meaning any user could use it. Originally, I had it “hard coded” to use my name, but found code here on the forum to get me my own user name, thus making it usable by any user on the system.


-- get full name
set theFullName to do shell script "niutil -readprop . /users/" & (do shell script "whoami") & " realname"
-- just use the first name
set myUser to word 1 of theFullName

tell application "Mail"
	activate
	set myText to (the clipboard) as string
	-- create a name for the the signature in Mail using first 3 words
	copy (word 1 of myText & space & word 2 of myText & space & word 3 of myText) to myName
	copy "--" & return ¬
		& myUser & return ¬
		& return ¬
		& myText to myText
	-- Run it past the user for approval
	display dialog ¬
		("Name: " & myName & return ¬
			& "Sig: " & return ¬
			& myText & return ¬
			& return ¬
			& "Is this ok?") as string
	if the button returned of the result is "OK" then make new signature with properties {name:myName, content:myText}
end tell