1

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

2 Answers 2

1

I'm not sure about the permissions issue exactly, but I get no error when I use "file" in the line you are referencing.

save theAttachment in file savePath

Where savePath is an alias to a file. If the alias already exists (for example as a template that you copy to that location), then you should have no permissions problems by saving the attachment into it.

6

A few years late to this party. However, in case anyone else has the same problem, this seems to be the necessary AppleScript syntax these days:

save theAttachment in POSIX file thePath

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .