Script not working after upgrading from 10.6 to 10.12

I have this script that sends an email with an file to be enclosed that is stored on the desktop. It worked for years under 10.6 and has stopped working since I upgraded to 10.12 two days ago

I can for the life of me not work out why it does not work. Anybody see what is wrong?

Here is the script:

set dFolder to "/Users/me/Desktop/"


tell application "Finder" to try
	set tFiles to ((every file whose name contains "XYZ")) as alias list
on error
	set tFiles to ((every file whose name contains "XYZ")) as alias as list
end try

set docfolderpath to path to desktop folder as string
set yourfolder to "~/Desktop/"
--------- the folder with the documents
set pathtoyourfolder to docfolderpath & yourfolder & ":" as string
set FNDVAR to "XYZ"
--------the "FIND" variable for the files
set ppath to quoted form of POSIX path of pathtoyourfolder
set theSender to "me@abc.com"
set thercpnt to "person@qwerty.com"
---------one could have a list here and do a repeat
set theFiles to (do shell script "mdfind -onlyin " & "~/Desktop/" & " 'kMDItemDisplayName == \"*" & FNDVAR & "*\"'")
------seems to be faster than finder I concluded long ago
set theattachmentspaths to {}
------preparing list for attachment paths
repeat with x from 1 to the count of paragraphs in theFiles
	set theF to alias POSIX file (paragraph x of theFiles)
	set end of theattachmentspaths to theF
end repeat
tell application "Finder"
	set theSubject to short date string of (current date) & (" - text as you like")
	------- change as needed
	set theBody to "
	text body"
	------- change as needed
	tell application "Mail"
		delay 2
		--------this line below is where it stops
		set newMessage to make new outgoing message with properties {address:thercpnt, subject:theSubject, content:theBody & return & return}
		tell newMessage
			-----end
			set visible to true
			set sender to theSender
			make new to recipient at beginning of to recipients with properties {address:thercpnt}
			repeat with y from 1 to count of items in theattachmentspaths
				delay 2
				set theAttachment to item y in theattachmentspaths
				tell content
					make new attachment with properties {file name:theAttachment} at after the last paragraph
				end tell
				delay 2
			end repeat
		end tell
		delay 2
		send newMessage
	end tell
	activate
end tell

Mail got an error: Can’t make {address:“person@qwerty.com”, subject:“31/10/2018 - text”, content:"
text body

"} into type properties of outgoing message.

Thanks for your help.

As the problem is in the part supposed to create the new message I post only the relevant code.

set thercpnt to "person@qwerty.com"
set theSender to "me@abc.com"
set theSubject to short date string of (current date) & (" - text as you like")
------- change as needed
set theBody to "
	text body"
------- change as needed
tell application "Mail"
	delay 2
	-------- the code below was tested under 10.13.6
	set newMessage to make new outgoing message with properties {sender:theSender, subject:theSubject, content:theBody & return & return}
	tell newMessage
		make new to recipient at end of to recipients with properties {name:"trucmuche", address:thercpnt}
	end tell
end tell

I’m surprised to read that your original code worked well because the syntax used above was already used in Learn AppleScript 3rd Edition, copyright 2010 which was during the availability of 10.6.

For my own use, I would drop the use of a “tell Finder” block.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 31 octobre 2018 19:32:55

Thanks Yvan,
indeed it was working in 10.6, as said I just upgraded. will test tomorrow.

Hi Yvan, I tested it (sorry it took so long…) and it does not work with Microsoft Outlook 2011 (you used Mail which I do not use)

I get en error: Microsoft Outlook got an error: Can’t make class outgoing message.

it highlights this line: make new outgoing message with properties {sender:theSender, subject:theSubject, content:theBody & return & return}

any solutions?

Hi ChangeAgent.

Your posted script clearly says application “Mail”. It would help others to help you if you gave the correct information, not blame them for being misled.

o-dear o-der Nigel, how stupid one can get. I picked the wrong thread to post. Will post the question separately in a new post. So sorry!

As to this one I could not get it to work and made an Automater script (with AS elements in it) that seems to do it. but thanks for all the help.