Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

applescript save mail attachment (10.10) Yosemite

I have a script that I run to save pdf attachments that come in via email. This script has served me well till this latest upgrade. Once I installed Yosemite (OS X 10.10) the script stopped working. I have dug around but cannot find a solution. Can someone please look at this and explain what is failing and how I can fix it?

Thank you for your time.

Mano

using terms from application "Mail"
    on perform mail action with messages theMessages --for rule theRule
        -- Only use hardcoded path! DO NOT USE choose folder. It will crash Mail if you do
      
        -- Script modified for 10.8 on 09/12/13 MV
        -- as of Mac OS X 10.8 Mail.app applescripts can only save to the downloads directory
        -- the shell script below moves the file from downloads to its proper place for processing
        set theOutputFolder to "MyComputer:Users:me:Downloads:" -- replace quoted text with your desired path
        set theNextDelivery to "NextDelivery.pdf"
        tell application "Mail"
            repeat with theMessage in theMessages
                if theMessage's mail attachments is not {} then
                    repeat with theAttachment in theMessage's mail attachments
                        set theFileName to theOutputFolder & theNextDelivery
                        --display dialog ("Filename ")
                        try
                            save theAttachment in theFileName
                        on error errnum
                        end try
                    end repeat
                end if
            end repeat
        end tell
    end perform mail action with messages
  
    do shell script "/Users/me/Documents/Scripts/Fuel_Next_Delivery/NextDelivery.sh"

end using terms from

OS X Yosemite (10.10), 16GB RAM

Posted on Oct 28, 2014 12:33 PM

Reply
3 replies

Nov 21, 2014 2:51 AM in response to mvasilakis13

Try this, it's working.


using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        tell application "Finder" to set attachmentsFolder to ("/Users/yatkha/Downloads/GmailAttachments") as text
        tell application "Mail"
           
            repeat with eachMessage in theMessages
                set adrress to (sender of eachMessage)
                if adrress contains "<" then
                    set AppleScript's text item delimiters to {"<"}
                    set theSender to text item 2 of adrress
                    set AppleScript's text item delimiters to {">"}
                    set theSender to text item 1 of theSender
                    set AppleScript's text item delimiters to {""}
                else
                    set theSender to adrress
                end if
               
                set {year:y, month:m, day:d, hours:h, minutes:min} to eachMessage's date received
                set timeStamp to (y & my pad(m as integer) & my pad(d) & my pad(h) & my pad(min)) as string
               
                set attachCount to count of (mail attachments of eachMessage)
                if attachCount is not equal to 0 then
                    if (do shell script "/bin/test -e " & quoted form of ((POSIX path of attachmentsFolder) & "/" & theSender) & " ; echo $?") is "1" then
                        do shell script "/bin/mkdir -p " & quoted form of ((POSIX path of attachmentsFolder) & "/" & theSender)
                    end if
                    try
                       
                        repeat with theAttachment in eachMessage's mail attachment
                            set originalName to name of theAttachment
                            set theAttSize to file size of theAttachment
                            set savePath to attachmentsFolder & "/" & theSender & "/" & timeStamp & " " & originalName
                            try
                                if theAttSize > 2000 then
                                    save theAttachment in savePath
                                end if
                            end try
                        end repeat
                       
                    end try
                end if
            end repeat

applescript save mail attachment (10.10) Yosemite

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.