Setting The Signature for a New Message in Apple Mail

I’ve got a script (relevant code below) that takes the file passed to it and attaches it to a new outgoing message in Mail.

Even though Mail is set to use a particular signature for each new message, the script-created message has no signature.

I’d like to tell Mail to use a given signature for the newly create message. At the moment, all I get is an AppleScript handler error.

		tell application "Mail"
			set the new_message to ¬
				(make new outgoing message with properties ¬
					{visible:true, content:" "})
			tell the new_message
				set message signature of new_message to signature "ITD"
				tell content
					make new attachment with properties ¬
						{file name:target_file} at ¬
						after the last paragraph
				end tell
			end tell
		end tell

I’ve experimented with where to place the signature line-at the beginning and at the end of the tell block. Neither one works.

I’ve found an older reference to specifying signatures in:

I’ve tried both methods outlined in the post, but the script fails at the point of specifying the signature. In Script Debugger I have the error sheet with a -10,000 in the lower left.

When I look at Mail’s Dictionary, I find:

I’m trying to get this to work in Mojave 10.14.5/6.

Thanks for any guidance you can offer.

Cheers,
Jon

If my memory is right, the feature Signature is broken since Tiger.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 2 août 2019 18:13:48

Yvan,

I did see some reports that it was broken, but nothing for recent OS versions, so I was hoping it was fixed and I was messing something up in the syntax.

Thanks for the info.

Cheers,
Jon

It’s just today that the need for using a signature arose with me. Despite the script compiling and double-checking hierarchic relations, execution of the script repeatedly returned the AppleScript handler error. Googling revealed a tone of people having the same issue and it appears it’s a long playing bug sent to negligence by Apple. Some people claimed they were able to use this Mail OM element successfully in version prior to Sierra (10.12), however I can claim confidently that it existed as early as in Mavericks which I run now.
I didn’t try to test it in High Sierra and Lion but I have no faith it will work there.

Model: MacBook Pro
AppleScript: 2.3.2
Browser: Safari 9537.86.7
Operating System: macOS 10.9

Yes, I’m perfectly aware about that however I came up with an easier solution. GUI scripting tends to be unreliable and the fact that UI elements animate with a varying speed every time you fire up GUI automation leads to random fails. Instead, I propose to extract the content of a signature using its property “content” which is text and append it to the outgoing message’s content property, like so:

set TheSgn to get content of signature NameOfTheSinature
set content to BodyOfTheMessage & return & return & return & return & TheSgn

The scripting context is implied so I dumped it here.

As you see, it’s just 2 lines and it makes the whole difference. Blame Apple for outlandishly putting the fix off and for making people go all out to fill up this omission in their OS.

Model: MacBook Pro
AppleScript: 2.3.2
Browser: Safari 9537.86.7
Operating System: macOS 10.9

Unfortunately this workaround fails with macOS Mojave’s Mail app…

(I’m currently unable to test with later versions of macOS.)

I heard that in some intermediate versions of OS X the message signature property was broken.

This is one aspect, but there is another important error in the original topic script - the signature that originally belongs to the outgoing message does not exist. Initially, it belongs to the application.

The following script works on Catalina. Note that I specify who owns the signature (of application “Mail”):
 

set target_file to "/Users/123/Desktop/MacScripter .webloc"

tell application "Mail"
	
	-- return signatures --
	--> {signature "Signature #1", signature "Signature #2", signature "Signature #3", signature "NewSignature", signature "NewSignature", signature "NewSignature", signature "Kniazidis Robert", signature "Signature #4"}
	
	set the new_message to (make new outgoing message with properties {visible:true, content:" "})
	tell the new_message
		set message signature of new_message to signature "Signature #1" of application "Mail"
		tell content
			make new attachment with properties {file name:target_file} at ¬
				after the last paragraph
		end tell
	end tell
	
end tell

 

It fails on Mojave, but I’m happy to hear Apple spent a least a little effort fixing a very longstanding bug.