The following works in Mojave, to attach a file to a new message:
on send_email(myAttachment)
tell application "Mail"
activate
set theMessage to make new outgoing message
tell theMessage
set filefn to (POSIX file myAttachment) as Unicode text
tell content to make new attachment with properties {file name:filefn as alias} at after last paragraph
end tell
end tell
end send_email
send_email("/path/to/file")
on send_email(myAttachment)
set filefn to (POSIX file myAttachment)
tell application "Mail"
activate
set theMessage to make new outgoing message
tell theMessage
tell content to make new attachment with properties {file name:filefn as alias} at after last paragraph
end tell
end tell
end send_email
A repeat with inside tell application Mail gives a similar error as before, while constructing a new list outside tell application Mail (as in your code) and then using that new list inside produces no error but also doesn’t attach the files.
on send_email(myAttachments)
repeat with i from 1 to count of items of myAttachments
set item i of myAttachments to (item i of myAttachments) as POSIX file
end repeat
tell application "Mail"
activate
set theMessage to make new outgoing message
tell theMessage
repeat with aFile in myAttachments
tell content to make new attachment with properties {file name:aFile} at after last paragraph
end repeat
end tell
end tell
end send_email
@TedTedTed: You can get rid of a lot of type conversions (and of a second repeat loop in this case) if you are using HFS paths (“Macintosh HD:path:to:file.ext”). There are APIs for all standard folders without hard-coding the path
on send_email(myHFSAttachments)
tell application "Mail"
activate
set theMessage to make new outgoing message
tell content of theMessage
repeat with anAttachment in myHFSAttachments
make new attachment with properties {file name:(alias anAttachment)} at after last paragraph
end repeat
end tell
end tell
end send_email