Q: Applescript to choose a message in mail & download its attachment
Hi,
I'd like to know if there's a way to prompt the user to choose a mail message like how we are able to choose file / folder?
Mainly, I'd like the process to go like:
Choose a mail, download its attachment, perform actions on the attachment.
I'm stuck at how I can reference a message as well for the downloading of the attachment. ATM, I'm only able to get the message ID by already selecting the mail message in Mail, and doing "set my_Sel to get selection".
Thank you.
OS X El Capitan (10.11.4)
Posted on Jun 16, 2016 11:39 PM
This fails because of the line:
set theMessageID to get selection
'get selection' will aways return a list, even if there is only one message selected - heck, even if there are no messages selected, you'll still get a list back... it'll just be empty.
That's why the script fails when you try to:
set theMessage to message theMessageID
because you can't coerce a list to a message.
The solution is simple... extract the message from the list:
set theSelectedMessages to get selection
set theMessage to first item of theSelectedMessages
Now you can act on theMessage.
Alternatively, maybe there is a case where you want to support multiple selected messages, in which case you could just iterate through theSelectedMessages and process them in turn.
set theSelectedMessages to get selection
repeat with eachMessage in theSelectedMessages
...
end repeat
Posted on Jun 17, 2016 1:55 PM