As per various code snippets on the web I am trying to implement a simple AppleScript to save the attachments of Mail messages to a folder.
set thePath to ((path to home folder as text) & "Documents")
tell application "Mail"
set selectedMessages to selection
set theMessage to item 1 of selectedMessages
set theAttachments to theMessage's mail attachments
repeat with theAttachment in theAttachments
set originalName to name of theAttachment
set savePath to (thePath & ":" & originalName)
display dialog ("Saving attachment to " & savePath)
save theAttachment in savePath
end repeat
end tell
Here is what the dialog box reports when I run the script with one message selected in Mail that has an image attached:
Saving attachment to Macintosh HD:Users:billtubbs:Documents:20180415_103233.jpg
Here is the error message I get:
error "Mail got an error: To view or change permissions, select the item in the Finder and choose File > Get Info." number -10000
It is raised on the line
save theAttachment in savePath