Saturday, March 28, 2020

#1 2020-03-26 08:20:23 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 269

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:


Applescript:


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.

AppleScript: 2.10 (194)
Browser: Safari 605.1.15
Operating System: macOS 10.13

Offline

 

#2 2020-03-26 09:17:56 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4039

Re: Upgraded server from 10.12 to 10.13 and email script stopped working

Are you sure that this group of instructions ever gave a valid result ?

Applescript:

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

I'm sure that it never did.

It returns something like :
"'/Users/**********/Desktop/~:Desktop:/'"
which isn't a valid path.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 26 mars 2020  16:17:50

Offline

 

#3 2020-03-26 09:42:07 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 269

Re: Upgraded server from 10.12 to 10.13 and email script stopped working

Yvan thanks.  my wrong, this is not the correct script I posted.  and I found the error in the other one.  your post made me look so in a way you helped!

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)