I would appreciate your help with the following problem. Using some code found here I (new to AppleScript) wrote the following script to iterate through a folder of specially named files to send each file to the user name embedded in the file. All works well up through composing the emails, but the messages are left open in mail and are not sent. Am I using the send command incorrectly?
tell application "Finder"
set fileCount to (count files in folder folderName)
set output to ""
repeat with i from 1 to fileCount
set fileName to (the name of file i in folder folderName)
set userName to item 3 of (splittext fileName using "_")
set pathName to "/Users/jhmiii/Desktop/" & folderName & "/" & fileName
-- change pathname as needed to point to location of your folder
set theAddress to userName & emailAddress
tell application "Mail"
activate
set newMessage to make new outgoing message with properties {visible:true, subject:fileName, content:theBody}
tell newMessage
set sender to theSender
make new to recipient with properties {name:userName, address:theAddress}
tell the content to make new attachment with properties {file name:pathName} at after the last paragraph
end tell -- newMessage
send {outgoing message:newMessage}
end tell -- application
end repeat
end tell -- finder
Model: Powerbook
AppleScript: 2.1.2
Browser: Safari 534.50
Operating System: Mac OS X (10.6)
tell application "Finder"
set fileCount to (count files in folder folderName)
set output to ""
repeat with i from 1 to fileCount
set fileName to (the name of file i in folder folderName)
set userName to item 3 of (splittext fileName using "_")
set pathName to "/Users/jhmiii/Desktop/" & folderName & "/" & fileName
-- change pathname as needed to point to location of your folder
set theAddress to userName & emailAddress
tell application "Mail"
activate
set newMessage to make new outgoing message with properties {visible:true, subject:fileName, content:theBody}
tell newMessage
--set sender to theSender
make new to recipient with properties {name:userName, address:theAddress}
tell the content to make new attachment with properties {file name:pathName} at after the last paragraph
--end tell -- newMessage
send --{outgoing message:newMessage}
end tell
end tell -- application
end repeat
end tell -- finder
here is an example that sends mail with an attachment
set fileName to "subject"
set theBody to "body text"
set userName to "Budgie"
set theAddress to "email address"
set pathName to "path to your image" as alias
tell application "Mail"
activate
set newMessage to make new outgoing message with properties {visible:true, subject:fileName, content:theBody}
tell newMessage
make new to recipient with properties {name:userName, address:theAddress}
tell the content to make new attachment with properties {file name:pathName} at after the last paragraph
send
end tell
end tell
Thanks for the reply. Moving the ‘send’ command into the ‘tell newMessage’ block remedied he problem. Sent the script to my son who needed the automation, but was unable to use Automator to make it work. Appreciate your help.