I took the script from http://www.macosxhints.com/article.php?story=20060420065151134 and modified it so it would actually set the subject field and add the current attachment but…
The only problems I am having now is mail says recipients not defined but clearly they are “make new to recipient with properties {address:“E@EMAIL.COM”}”
whats wrong with the script to make mail display that error
The script is
using terms from application "Mail"
on perform mail action with messages actionMail for rule actionRule
tell application "Mail"
repeat with i from 1 to count of actionMail
set thisMail to item i of actionMail
set theSubject to the subject of thisMail
set theBody to (the content of thisMail) as text
set theBody to my getFirstLine(theBody)
try
if theSubject contains "<launch>" then
my launchApp(theBody)
else if theSubject contains "<say>" then
my sayThis(theBody)
else if theSubject contains "<do>" then
my doShell(theBody)
else if theSubject contains "<send>" then
my sendThis(theBody)
else if theSubject contains "<put>" then
set attachName to the name of the first mail attachment of thisMail
try
save first mail attachment of thisMail in theBody & attachName
on error
set newMessage to make new outgoing message with properties {subject:"I was not able to put the file you sent in the requested place"}
tell newMessage
set visible to true
make new to recipient with properties {address:"E@EMAIL.COM"}
end tell
send newMessage
end try
else if theSubject contains "<script>" then
do shell script "osascript -e '" & theBody & "'"
end if
end try
end repeat
end tell
end perform mail action with messages
end using terms from
on launchApp(theApp)
tell application theApp to activate
end launchApp
on sayThis(theText)
say theText
end sayThis
on doShell(theShell)
do shell script theShell
end doShell
on sendThis(theFile)
try
set theFile to theFile as alias
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:"Please find attached the file you requested"}
tell newMessage
set visible to true
make new to recipient with properties {address:"E@EMAIL.COM"}
make new attachment with properties {file name:theFile} at before the last paragraph
end tell
send newMessage
end tell
on error
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:"I was not able to send you the file you requested"}
tell newMessage
set visible to true
make new to recipient with properties {address:"E@EMAIL.COM"}
end tell
send newMessage
end tell
end try
end sendThis
on getFirstLine(theBody)
set oldTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "
"
set firstLine to text item 1 of theBody
set AppleScript's text item delimiters to oldTID
return firstLine
end getFirstLine