问题
I've worked out (found online) how to attach a single item from Finder to a new Outlook message. I've played with this format a good amount - changed 'selecteditem' and selection and some other more major changes - but I can't work out how to get more than one item to attach to a new outlook message at a time.
Only a single item attaches to each new outlook message. There are no Outlook Automator options in Automator - I think Office 365 did away with them.
My current script is as follows:
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
I'm currently trying use this script in Automator as a service so I have a right click option to send files directly to a new Outlook message. It's currently setup like this.
回答1:
Your Automator Service gets "Files or Folders" from Finder. This part is OK. Just the content of the applescript must be changed.
To read these inputs (the selected files from Finder), you must use the "on run" handler where "input" will be the selected files.
The script bellow must replace your current script. I assumed that the subject of your email should be the name of the first selected file in case of multiple selection:
on run {input, parameters}
set SelectedItems to input
tell application "Finder" to set fileName to name of first item of SelectedItems
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {subject:fileName}
tell newMessage
repeat with aFile in SelectedItems -- the loop through all selected items
make new attachment with properties {file:aFile}
end repeat
end tell
open newMessage
get newMessage
end tell
return input
end run
On top of that, I have 2 comments :
1) this script does not filter the case when you select a folder. Inside the loop, you may want to add a "if" test to check file or folder and take action in case selection is a folder.
2) I do not understand the overall process you want to perform: Select files, go to menu Service to run this service, which creates a new Outlook message with these files as attachment...You can do all this by just selecting the files and drag/drop them on the Outlook icon in the dock. it will immediately create a new blank message with all the attached files.
来源:https://stackoverflow.com/questions/36806427/using-an-applescript-automator-to-attach-multiple-items-to-a-new-outlook-message