How to fix AppleEvent handler failed error with command "make new mailbox with properties"
Below is the script I am running to create a hiearchy of new mailboxes inside "ON MY MAC" folder area.
tell application "Mail"
makenewmailboxwith properties {name:"ABar"}
makenewmailboxwith properties {name:"ABar/Foo"}
makenewmailboxwith properties {name:"ABar/Foo/Me"}
end tell
When I execute this the first mailbox is excuted fine but right afterwards I get the following error:
error "Mail got an error: AppleEvent handler failed." number -10000
I have tried adding delays but this does not work either. Code:
tell application "Mail"
makenewmailboxwith properties {name:"ABar"}
delay 0.2
makenewmailboxwith properties {name:"ABar/Foo"}
delay 0.2
makenewmailboxwith properties {name:"ABar/Foo/Me"}
end tell
However rerunning the script and skipping over the make command if the folder already exit, causes the next exuction time to create one more folder.
Code:
tell application "Mail"
if (mailbox "ABar" exists) = false then
makenewmailboxwith properties {name:"ABar"}
delay 0.2
end if
if (mailbox "ABar/Foo" exists) = false then
makenewmailboxwith properties {name:"ABar/Foo"}
delay 0.2
end if
if (mailbox "ABar/Foo/Me" exists) = false then
makenewmailboxwith properties {name:"ABar/Foo/Me"}
delay 0.2
end if
end tell
** Anyone know how to solve this or why this is happening? **
It almost feels as if the hiearcgy is read into memory and this is not updated after the creation of the new mailbox.
Thanks!
MacBook Pro (15-inch Early 2011), OS X Mavericks (10.9.1), Applescript mailbox