Mail Script - Signature

I’m trying to set a signature in my outgoing mail message, but it’s not working :


tell application "Mail"
	set nieuwBERICHT to make new outgoing message with properties {visible:true, sender:"Jan Geerling<jan@str8.nl>", subject:"TEST"}
	delay 2
	tell nieuwBERICHT to set message signature to "JAN-NL"
	delay 2
	tell nieuwBERICHT to make new attachment with properties {file name:orderbevestigingPDF} at after last paragraph
end tell

And this script only give ‘missing value’


tell application "Mail"
	set everySignature to the name of every signature
end tell

Is that a bug ?

I can confirm that in Sierra it doesn’t work but it does work in El Capitan. Somehow signature is broken in Mail version 10. The dictionary still says signature is an application class so the code is correct. I think you’re right and you’ve found a bug in mail.

Hi

This handler works


emailattachments("zzzzzz@me.com", "xxxx", "xxxxx")
on emailattachments(theAddress, theSubject, theBody)
	
	tell application "Mail"
		set theSignature to signature "New Signature"
		set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody}
		tell newMessage
			set visible to true
			
			make new to recipient at end of to recipients with properties {address:theAddress}
			
			set message signature to theSignature
		end tell
		
		--send newMessage
	end tell
	
end emailattachments


I just tried weedinner’s script on 10.13 and the first error was that it couldn’t find the signature by it’s name. Then when I changed it to just look for the “first signature”, the script fails when trying to set the signature on the message with a very cryptic “Mail got an error: AppleEvent handler failed.”

Can anyone on 10.14 or 10.15 confirm if this is still an issue?

It is simple: signature “New signature” doesn’t exist on your Mail.app. To get the existing signatures list on your Mail.app you can run this:

tell application "Mail" to every signature

I said already on related topic that getting signature properties name and content is broken on Mojave (10.14, It seems, on 10.13 too), so you get that error. When you run

set message signature to theSignature

AppleScript tries to get this 2 properties as list and as they are broken, AppleScript fails. You can’t avoid here GUI scripting.

And, even with GUI scripting this concrete signature (signature “New signature”) should be already one of the attached signatures to account, from which you create outgoing message. You should first attach some signatures to your account in the preferences. Only then you can choose one of them in the script. And only with GUI scripting