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.