Upgraded server from 10.12 to 10.13 and email script stopped working
I have the following script on my Mac Mini headless server, that sends me pictures of the desktop if a shut down fails. That way I can see what is causing it.
After the upgrade to OS 10.13.6 (highest it can run), this script no longer works. I did loads of trying and testing but do not get it to work. I must oversee something I think.
Here is the script:
set dFolder to "/Users/ganesh/Desktop/"
repeat 1 times -- Repeat XX times.
set tTime to do shell script "date +%T"
set dDate to do shell script "date +%d"
do shell script ("mkdir -p " & dFolder)
do shell script ("/usr/sbin/screencapture " & dFolder & dDate & "-time-" & tTime & ".png") -- Capture screen.
delay 1 -- Wait for xx seconds.
end repeat
tell application "Finder" to try
set tFiles to ((every file whose name contains "-time-")) as alias list
on error
set tFiles to ((every file whose name contains "-time-")) 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 "-time-" --------your "FIND" variable for the files
set ppath to quoted form of POSIX path of pathtoyourfolder
set theSender to "xxx@xxx.com"
set thercpnt to " xxx@xxx.com" ---- you 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
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) & (" Shutdown Failed > PNG") --- change as needed
set theBody to "Pics enclosed" --- change as needed
tell application "Mail"
delay 2
set newMessage to make new outgoing message with properties {address:thercpnt, subject:theSubject, content:theBody & return & return}
tell newMessage
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
I get the following error:
error "Mail got an error: Can’t make {address:\" xxx@xxx.com \", subject:\"26/03/2020 Shutdown Failed > PNG\", content:\"Pics enclosed
\"} into type properties of outgoing message." number -1700 from {address:" xxx@xxx.com ", subject:"26/03/2020 Shutdown Failed > PNG", content:"Pics enclosed
"}
Anybody got an idea as to why? Thanks.