convert from applescript to osascript for shell

Ahti Ta's icon

Hi,

can anyone help me out with converting the following applescript to osascript message for shell:

tell application "Mail"

set theSubject to "Subject"

set theContent to "Content sentence"

set theAddress to "dynamicemailaddress@gmail.com"

set theAttachmentFile to "Macintosh HD:Users:xyz:Desktop:dynamicaddress.png"

set msg to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}

tell msg to make new to recipient at end of every to recipient with properties {address:theAddress}

tell msg to make new attachment with properties {file name:theAttachmentFile as alias}

delay 3

send msg

end tell

----
Thanks

Source Audio's icon

As You don't have any changable arguments in that script,
easier would be to save the script as app, and execute it from max.
You even don't need shell to execute it, a message like :
;
max launchbrowser "file:///Users/xyz/Desktop/My-Script
.app"

would do.

Ahti Ta's icon

I do. I need to change the email and attachment file name dynamically...

Source Audio's icon

This is a bit complex thing, I don't use Mail.app to test it , but here is the rule :
every tell must be enclosed like -e 'tell to do whatever'
mind You the punctuation ' here is ascii 39
and all items in applescript wich need to be enclosed by quotation marks
must look like this : \"TextEdit\"
examples :
osascript -e 'tell application \"TextEdit\" to activate make new document at the front'

osascript -e 'tell application \"TextEdit\" to activate' -e 'tell application \"System Events\"' -e 'tell process \"TextEdit\" to click menu item \"Close\" of menu \"File\" of menu bar 1' -e 'end tell'

Your next problem is passing attatchment path to Mail

From what I know shell itself accepts slash boot paths
like: /Volumes/Big-Hd/My-Stuff/textfile.txt
if You send it path like : Big-Hd:/My-Stuff/textfile.txt
it will not accept it.
But You are passing the path to Mail via shell, so You have to experiment and see what works.
Here is a patch that might work, please check it all I am not sure if I typed everything
correctly

Max Patch
Copy patch and select New From Clipboard in Max.