I am trying to create a mailbox inside a existing mailbox by using apple script .As per the requirement script has to check the predefined standard names of mailboxes in in the existing mailbox , and if it is not there just create a mailbox in the existing mailbox. I am trying to create it , but getting stuck with this error - Mail got an error: NSInternalScriptError . Is anybody having any solution or suggest me where I can get solution , please help me in this case.
–this mailbox is at level one
set parent_mailbox to “dxbgen”
set child_mail_box to “jhon”
tell application “Mail”
set account_name to “IMAP Account”
tell account account_name
–trying to create the new mailbox
make new mailbox of mailbox parent_mailbox with properties{name:child_mail_box}
end tell
end tell
when I run this script , I got the following error :
Mail got an error: NSInternalScriptError
Please help me to get solution of this problem .
Thanks in advance
Best regards
krishna
Model: iMac
AppleScript: 1.10.6
Browser: Safari 417.9.2
Operating System: Mac OS X (10.4)
I think you need to specify the path to the mailbox in the name, like “dxbgen/jhon”.
You also say the mailbox is “level one”, are you sure it is contained by the account.
Try this:
--this mailbox is at level one
set parent_mailbox to "dxbgen"
set child_mail_box to "jhon"
tell application "Mail"
--trying to create the new mailbox
-- Check to see if this mailbox does not exist.
if not (exists mailbox (parent_mailbox & "/" & child_mail_box)) then
-- If it doesn't exist, make it.
make new mailbox with properties {name:parent_mailbox & "/" & child_mail_box}
end if
end tell
Thanks a lot for the reply , I just tried it and it worked fine. Can you suggest me one more thing that how I can get the mail boxes for particular level or atleast of the first level .
tell application "Mail"
set myList to mailboxes--mboxes
repeat with myAccount in accounts
set myList2 to (mailboxes of myAccount)--imapmboxes
set myList to myList & (contents of myList2)
end repeat
return myList
end tell
set first_level_list to {}
set first_level_mailbox to get_mailbox
repeat with mb_name in first_level_mailbox
set mb_name to mb_name as string
display dialog mb_name
end repeat
on get_mailbox()
tell application "Mail"
set myList to mailboxes --mboxes
repeat with myAccount in accounts
set myList2 to (mailboxes of myAccount) --imapmboxes
set myList to myList & (contents of myList2)
end repeat
return myList
end tell
end get_mailbox
i am getting following the error :
Can’t make «handler get_mailbox» into type reference.
Firstly, when you call a handler, you need to supply the same number of variables as the handler needs to operate. With the ‘get_mailbox()’ handler you created this is none, but you need to show the empty list. So, in you main script part call the handler with ‘get_mailbox()’ and not ‘get_mailbox’.
Secondly, the handler returns the references to the maiboxes, not the name of them. You’ll need to get the name to use in the display dialog. Take a look at the mailbox properties of Address Book’s dictionary in Script Editor.