Can someone please help me with a script?

Hi Guys,

Can someone please have a look at the below script and tell me how I can get it to work in El Capitan.

The script automatically sends an email to a distribution list when I add a file to a folder. (the file is added to the the email as an attachment and is automatically sent)

It worked perfect under Yosemite but under El Capitan, it sends the email but doesn’t attach the file to the email.

Can anyone please help?

Thanks in advance

[b]on adding folder items to thefolder after receiving theAddedItems

repeat with eachitem in theAddedItems

    

    

    

    

    set theSender to "Aide<adavies199@virginmedia.com>"

    set recipCommon to "Plex Friends"

    set recipAddress to "Plex Friends"

    

    set msgText to "A new movie has just been uploaded - Enjoy!"

    

    

    

    

    

    

    tell application "Mail"

        

        

        set newmessage to make new outgoing message with properties {subject:"A new movie has just been added to Movies", content:msgText & return & return}

        tell newmessage

            set visible to true

            set sender to theSender

            

            make new to recipient with properties {name:recipCommon, address:recipAddress}

            make new attachment with properties {file name:eachitem} at after the last paragraph

            

            

        end tell

        send newmessage

    end tell

    

    

end repeat

end adding folder items to[/b]

Hello

Which kind of file are you trying to attach ?

I tested your script with two different files :

  • a flat one - in fact a PDF
  • b a package, namely a rtfd item.
    It behaved well for them so I’m a bit puzzled.

Yvan KOENIG running El Capitan 10.11 in French (VALLAURIS, France) lundi 28 septembre 2015 21:07:40

HI and thanks for your reply

I’t’s just a text file

OK

Assuming that your machine may not behave with the same speed than mine, you may try to insert a delay:

make new to recipient with properties {name:recipCommon, address:recipAddress}
delay .2
make new attachment with properties {file name:eachitem} at after the last paragraph

In my tests, the path to the file to attach was embedding only ASCII characters, no accented chars which are commonly used in France. Double check the spelling of your files.

If you can’t get the script to behave well, you may try to use a droplet and drop the files to attach on its icon.

Oops, I was forgetting a detail : which is the language used by your system ?
Here I use French (don’t worry about my signature, after testing I moved back in Yosemite.

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) lundi 28 septembre 2015 22:15:32

Hi,

I have added the delay .2 into the script but it’s still not attaching the txt file.

I just don’t know what else to try

Can anyone please help?

Actually the correct syntax is to create the attachment in the content of the message.

tell content
	make new attachment with properties {file name:eachitem} at after the last paragraph
end tell

I’ve added:-

tell content
make new attachment with properties {file name:eachitem} at after the last paragraph
end tell

but it’s still not attaching the text file - the email sends fine but no attachment

Here is the the script in full as it stands:-

on adding folder items to thefolder after receiving theAddedItems
	
repeat with eachitem in theAddedItems
		
		set theSender to "Aide<adavies199@virginmedia.com>"
		set recipCommon to "Plex Friends"
		set recipAddress to "Plex Friends"
		
		set msgText to "A new movie has just been uploaded - Enjoy!
		
		tell application "Mail"
			
			set newmessage to make new outgoing message with properties {subject:"A new movie has just been added to Movies (Temp)", content:msgText & return & return}
			tell newmessage
				set visible to true
				set sender to theSender
				
				make new to recipient with properties {name:recipCommon, address:recipAddress}
				delay 0.2
				
            tell content
		
				make new attachment with properties {file name:eachitem} at after the last paragraph
				
			end tell
			send newmessage
		end tell
		
		
	end repeat
	
end adding folder items to

Could you please use the applescript tags for the code and avoid multiple empty lines

Can anyone, please help??

Thanks in advance

I’m having the same issue. This script worked up until 10.11 El Cap. Now no attachments. I’m seeing other posts around about apps that no longer can attach files (I read about Quickbooks and others).

Would appreciate a simple script that someone has confirmed works with 10.11.

I’ve put a delay in several places since it does appear to send very fast in 10.11 vs a slight delay I recall while it was building the email. But no use.

Here’s my simple script.

tell application “Mail”
set theMessage to (a reference to (make new outgoing message at beginning of outgoing messages))
tell theMessage
make new to recipient at end of to recipients with properties {name:“”, address:"tom@tom.com"}
set the subject to “Invoice #00000002; From me”
set the content to “Please contact us immediately if you are unable to detach or download your Invoice. Thank you.”
tell content
make new attachment with properties {file name:(alias “MacintoshHD:users:myuser:test.pdf”)} at after the last word of the last paragraph
end tell
end tell
send theMessage
end tell

There does seem to be a nasty bug in El Capitan’s Mail.

I have this working on my system. (OSX 10.11.1)

Note the delay at the bottom.


-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/11/01 02:32 
# dMod: 2015/11/01 06:19 
# Appl: Mail
# Task: Attempting to compensate for attachment bug in El Capitan's Mail.
# Tags: @Applescript, @Script, @Mail, @El_Capitan, @Attachment, @Bug
-------------------------------------------------------------------------------------------

set msgAddress to "Robert Heinlein <tanstaffl@pieinthesky.org>"
set msgSubject to "Just a Test"
set msgBody to linefeed & "This is my body.  There are many like it, but this one is mine..."
set msgSig to "Take_Care"
set attachmentAlias to alias "HD:Users:myUser:test:test_file.zip"

tell application "Mail"
	set msg to make new outgoing message with properties {subject:msgSubject, content:msgBody, visible:true}
	tell msg
		set message signature to signature msgSig of application "Mail"
		make new attachment with properties {file name:attachmentAlias} at before first paragraph
		make new to recipient at end of every to recipient with properties {address:msgAddress}
	end tell
	
	delay 1 -- CRITICAL “ change length of delay as necessary.
	send msg
	
end tell

-------------------------------------------------------------------------------------------


Chris


{ MacBookPro6,1 · 2.66 GHz Intel Core i7 · 8GB RAM · OSX 10.11.1 }
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

The adding of the delay worked for me as well.

tell content
make new attachment with properties {file name:“Macintosh HD:test.png” as alias} at after the last word of the last paragraph
end tell
delay 2

try

make new attachment with properties {path:eachitem}