Friday, November 16, 2018

#1 2018-10-31 05:42:51 am

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

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:

Applescript:

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.


Filed under: mail, Error, 10.12

Offline

 

#2 2018-10-31 12:44:06 pm

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

Re: Script not working after upgrading from 10.6 to 10.12

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

Applescript:

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

Last edited by Yvan Koenig (2018-10-31 12:45:55 pm)

Online

 

#3 2018-10-31 01:50:07 pm

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

Re: Script not working after upgrading from 10.6 to 10.12

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

Offline

 

#4 2018-11-07 01:26:56 am

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

Re: Script not working after upgrading from 10.6 to 10.12

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?

Last edited by ChangeAgent (2018-11-07 01:29:05 am)

Offline

 

#5 2018-11-07 03:07:43 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4720

Re: Script not working after upgrading from 10.6 to 10.12

ChangeAgent wrote:

and it does not work with Microsoft Outlook 2011 (you used Mail which I do not use)


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.


NG

Offline

 

#6 2018-11-07 03:33:32 am

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

Re: Script not working after upgrading from 10.6 to 10.12

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.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)