Workaround error number - 1719

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 :smiley:

Heres what I want to do:

  1. run script when specific Mail arrives in acertain Mailbox (E.g. “Air Plus”)
  2. 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 :frowning:

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 :frowning:

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 :slight_smile:

Thank you.

Hi,

you should refer to messages (plural) of the mailbox.
Anyway it’s not recommended to use large object tell blocks, try this


set savePath to "PATH"
tell application "Mail"
	set allMessages to messages of mailbox "Air Plus"
	repeat with aMessage in allMessages
		set aMessageIsRead to read status of aMessage
		try
			set nameOfAttachment to name of first mail attachment of aMessage
			if aMessageIsRead is false then save first mail attachment of aMessage in savePath & nameOfAttachment
		end try
	end repeat
end tell

Thanks that has worked!

But still I do not understand why my attempt did not work.
If you have the time could you please explain this, I don’t want to die stupid :smiley:

Again thanks for your help.