Mail app + AppleScript

Hi everyone!

I have a script which takes attachment from mails of iCloud account mailbox and save them to destination folder. All works perfect!

Today I imported my Microsoft Windows Outlook 2010 mail file .PST in Mail.app. It's saved to "On my Mac". But, when I call from script this path I have error message.


in first case I have this code and in work fine:


tellapplication"Mail"


settheMessages to messages of mailbox "INBOX" of account "iCloud"


repeat with aMail in theMessages

-- other part of code

----------------

end tell


When I try to access to "On my Mac" path it crashes:




ell application "Mail"


set theMessages to messages of mailbox "Imported" of  ( on my mac)


Is anyone can help to make correct request to "Imported" mailbox?

Posted on Mar 27, 2019 12:42 PM

Reply
Question marked as Top-ranking reply

Posted on Mar 28, 2019 12:47 PM

Oh, my bad - Mailboxes that are 'on my Mac' are not associated with any specific account, so you can just:


tell application "Mail"

get every mailbox

end tell


and you should be able to reference the message by simple mailbox name (without any 'account' data)

Similar questions

4 replies

Mar 28, 2019 11:01 AM in response to максимfromтула

No one here can tell you specifically what to write because everyone's Mail setup is slightly different.


However, if you run this script in Script Editor:


tell application "Mail"

get every mailbox of every account

end tell


You will get a list of all the mailboxes for all accounts - a quick dig through the account should be all that's needed to find the specific reference that Mail.app can use.


Mar 28, 2019 11:27 AM in response to максимfromтула

thanks for advice. This tip is good to understand how much mailboxes and accounts I have in mail.app. But problem still need to solve. In list of accounts are only iCloud account, whose don't consist target mailbox. I'am really don't understand in what place messages from other mailboxes imported. Here is screenshot of importing proccess in my Mac OS.


And here result of request in AppleScript after importing target mailbox and running script


Is there any tips to get name of imported mailbox?



This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Mail app + AppleScript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.