Hi there,
To be absolutely honest I am a complete newbie to apple script therefore I might ask a few stupid questions.
Note: I have changed the path (no need for you guys to know where I save my pdf’s
Heres what I want to do:
- run script when specific Mail arrives in acertain Mailbox (E.g. “Air Plus”)
- Script needs to download an attachment of an unread e-mail (only one attachment in this mail)
This is my first script:
set savePath to "PATH"
tell application "Mail"
tell message of mailbox "Air Plus"
set numberOfMessages to count
repeat with counter from 1 to numberOfMessages
set thisMessage to read status of item counter
try
set nameOfAttachment to name of first mail attachment of item counter
if thisMessage is (false) then save first mail attachment in savePath & nameOfAttachment
end try
end repeat
end tell
end tell
Now this script works when there is no E-Mail without an attachment in this Mailbox.
But if there is only one mail without an attachment then the scipt does nothing!
I get this error message:
get name of mail attachment 1 of item 2 of message of mailbox "Air Plus"
--> error number -1719 from mail attachment 1 of item 2 of message of mailbox "Air Plus"
I know that mail cannot get the right reference since there is no attachment there
Later on I get this message
get name of mail attachment 1 of item 5 of message of mailbox "Air Plus"
--> "22674781.pdf"
save mail attachment 1 of message of mailbox "Air Plus" in "PATH:22674781.pdf"
AS runs the script but does nothing
I have back-traced it to this error message mentioned above. Is there a way to circumvent this error?
I hope you guys can help me here
Thank you.