Apple script fail on copying attachment from Outlook

by hitzg   Last Updated October 11, 2018 15:12 PM

I'm trying to copy all the attachments that I received from a certain sender (scanner) to a folder. I'm using Outlook and I've tried to write a script to do the job. It fails on saving the file with error code:

error "Microsoft Outlook got an error: Parameter error." number -50

Unfortunately I've not been able to figure out a) what that error means, and b) how to make the script work. Any help is welcome.

This is my script:

set saveToFolder to (choose folder with prompt "Choose the destination folder") as string
set ctr to 0

tell application "Microsoft Outlook"
    set srcFolder to mail folder "inbox" of exchange account "FOO"
    set selectedMessages to messages of srcFolder
    repeat with msg in selectedMessages
        set ctr to ctr + 1
        set msgsender to the sender of msg
        set senderaddress to the address of msgsender
        if "[email protected]" = senderaddress then
            set attFiles to attachments of msg
            repeat with f in attFiles
                set attName to (get the name of f)
                log attName
                set saveAsName to saveToFolder & attName
                log saveAsName
                save f in POSIX file saveAsName
            end repeat
        end if
    end repeat
end tell
display dialog "" & ctr & " messages were processed" buttons {"OK"} default button 1
return ctr


Related Questions



Language selection on creating new email in Outlook Mac?

Updated September 07, 2016 08:05 AM

AppleScript and Excel : only keep email on cells

Updated April 05, 2017 14:12 PM

How to fix «event coreslct» error?

Updated May 18, 2016 08:05 AM