I would appreciate any input into my incomplete script.
I would like a script which adds a selected file as an attachment to a new Outlook message and uses the name of the selected file as the subject, with " :PDF Proof" appended.
I’m afraid I am still a trial and error scripter and I can’t find anything helpful to cannibalise!
tell application "Finder"
set selected_items to selection
set MessageSubject to selection as string
set theAttachment to selection
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {subject:MessageSubject}
tell content
make new attachment at the end of newMessage with properties {file:theAttachment}
end tell
open newMessage
end tell
end tell
I get the result “Can’t make (blah blah blah - file path) into the expected type.” number -1700
I’ve found that if I remove the line
tell content
make new attachment at the end of newMessage with properties {file:theAttachment}
Then I get a new message, but the subject line contains the full path of the selected file, rather than its name. I don’t know how to go about appending " :PDF Proof" as it doesn’t like the “:”.
I am using Outlook 14.1.4. I’m aware of a script that does exactly this for the “Mail” program, but I need to use outlook at work.
tell application "Finder" to set selectedItem to item 1 of (get selection)
set theAttachment to selectedItem as alias
set fileName to name of selectedItem
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {subject:fileName}
tell content
make new attachment at the end of newMessage with properties {file:theAttachment}
end tell
open newMessage
end tell
tell application "Finder" to set selectedItem to item 1 of (get selection)
set theAttachment to selectedItem as alias
set fileName to name of selectedItem
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {subject:fileName}
tell newMessage
make new attachment with properties {file:theAttachment}
end tell
open newMessage
end tell
Wow, that is doing the trick! It doesn’t actually open the new message, just puts it in the drafts folder, but I am able to live with that.
One more question though, is it possible to add additional text to the subject line? For example “TDO:” at the start, and " - PDF Proof" at the back? I guess I would do it in the “set filename” command at the start of the script, but I’m unable to add it in there without it becoming part of the variable.
tell application "Finder" to set selectedItem to item 1 of (get selection)
set theAttachment to selectedItem as alias
set TDO to "TDO: "
set Proof to "- PDF Proof"
set fileName to TDO & name of selectedItem & Proof
If anyone is interested, I’ve added an extra command at the bottom to open the message so you can type in the ‘to’ address, etc.
tell application "Finder" to set selectedItem to item 1 of (get selection)
set theAttachment to selectedItem as alias
set fileName to name of selectedItem
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {subject:fileName}
tell newMessage
make new attachment with properties {file:theAttachment}
end tell
open newMessage
get newMessage
end tell