Jump to content
Server Maintenance This Week. ×

email attachment using applescript


happymac

This topic is 3251 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I have a solution that creates an email with an attachment.  We need to use Applescript to do this, not the default 'send mail' function, and I am having trouble getting the applescript to attach the attachment.  What is strange is that some records, it works consistently, and other records it never works.

Basically I save a PDF to the desktop, then send an applescript command to use that attachment.  The desktop PDF always creates, the new mail message always creates with the recipient pulled from the fm database, but the attachment only sometimes attaches to the message.

In FileMaker, I am setting a variable with the applescript code, then after running the applescript which calls the variable.

the variable code is as follows ...

"set theAttachment to " & Quote( $MacPosixPath & $filename )  & "¶
set RecipientAddress to " & Quote ( estimate_CLIENTCONTACT__~fkclientcontact::email1 ) & "¶
set RecipientName to " & Quote ( estimate_CLIENTCONTACT__~fkclientcontact::name_full ) & "¶


tell application \”Mail\” ¶
set newMessage to make new outgoing message with properties {visible:true} ¶


tell newMessage ¶
make new to recipient with properties {name:recipientName, address:RecipientAddress} ¶

tell content of newMessage¶
make new attachment with properties {file name:theAttachment} at after the last paragraph¶
end tell¶ 

end tell¶ 
activate ¶
end tell ¶"

 

 

The variable $MacPosixPath is defined earlier in the script as ...

Substitute ( Right ($desktopPath ;  Length ( $desktoppath) - 1 ) ; "/"; ":")

and $desktoppath is simply defined as 

Get ( DesktopPath )

 

I have attached two images to this post showing the resulting applescript that is executed.  One that works correctly and the second that does not work.  In both cases the pdf is present on the desktop.  They look identical ... stange for sure!

 

thank you in advance!

 

 

applescriptThatDidNOTWork.png

applescriptThatWorked.png

Link to comment
Share on other sites

This topic is 3251 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.