I'm writing an Applescript so that I can attach a file to Outlook from the terminal in the following way:
$ attachToOutlook myreport.xlsx
Where attachToOutlook
is aliased to osascript /path/to/my/script/attach
This is my current implementation:
on run argv
tell application "Microsoft Outlook"
set theContent to ""
set theAttachment to item 1 of argv
set theMessage to make new outgoing message with properties {subject: ""}
tell content
make new attachment with properties {file: (item 1 of argv )} at the end of theMessage
end tell
open theMessage -- for further editing
end tell
end run
but I'm getting the following error:
attach:263:264: script error: Expected expression, etc. but found “:”. (-2741)
How can I fix this?
Best Answer
A couple of issues. First, you need to make the new attachment to the message, not to the content. Second, the attachment should be a posix file. Third, you can't just send a file name, you have to tell Outlook where the file is by including the full path.
I've written my own version included here, adding the subject and content as variables passed through the command line.
Note: Call with the following, replacing with the actual account name.
AppleScript code in
testterm.scpt
: