PDA

View Full Version : applescript select mailbox mail.app


felix
06-18-2010, 09:12 AM
Hello,
I need a very simple applescript for mail.app but I don’t find the way to do it and no thread about it.
I want to select in mail.app a specific mailbox of my gmail imap account. In my case the specific mailbox is the spam mailbox:
mailbox "[Gmail]/Spam" of account "B.L.M"
I want an applescript that selects it as I do it with a mouse click

Thanks,
F

renaultssoftware
06-18-2010, 11:20 AM
It's probably reveal mailbox "La Poste" -- your string here. I don't know but you try.

felix
06-19-2010, 11:18 AM
reveal doesn't seem to work ...
Any other idea? Come on, it must be very simple! :D
Thanks
F

renaultssoftware
06-19-2010, 01:19 PM
It would be simple if I were using a Mac... come on let's bug tw :)

Did you open Mail's dictionary and try everything?

tw
06-19-2010, 10:42 PM
the basic format is this:
tell application "Mail"
set selected mailboxes of message viewer 1 to {mailbox "Mailbox name"}
end tell
you'll probably have to be a bit tricky to if you want to reference smart mailboxes, and mail has some predefined referents like inbox and drafts mailbox that don't need the mailbox prefix.

also, I'm not sure if this will work in versions before 10.6. Mail applescript has historically (or maybe traditionally is a better word) been a bit bug-ridden.

felix
06-20-2010, 05:09 AM
Hi TW
Thank you very much.
This is what i was looking for ... it works perfect.
Best
F

osxpounder
08-25-2010, 10:58 AM
So, how does one tell Mail to select a certain Smart Mailbox?

Here's the problem I want to solve:

My company uses GroupWise IMAP. I use Mail for that account, with a smart mailbox named "GW Inbox" that collects all my sent mail and new mail, so that my threads include my replies.

So far, so good, but I can't get Mail to show me new appointments.

Incoming appointments go into a folder named "Calendar". Neither a Smart Mailbox nor a Mail rule will catch these and show them. The only way I know to check whether I received an appointment message is to click the Calendar folder myself. Only then will Mail load in and display appts.

Using script advice above, I wrote a script that will select the Calendar folder. Great! The appointments load in.

Now, I want the script to select the Smart Mailbox, "GW Inbox". I tried:

set selected mailboxes of message viewer 1 to {mailbox "Mailbox GW Inbox"}


... but I get an error: error "Mail got an error: AppleEvent handler failed." number -10000 from mailbox "Mailbox GW Inbox"

I also tried adding of account "GW IMAP" to that line, inside the curly braces, then outside. Same error.

How to do it?

Maybe I should start a new thread, but the current thread has already helped me a lot and this Q builds on the thread's topic.

renaultssoftware
08-25-2010, 11:53 AM
I can't figure out how to select a smart box either

NaOH
04-14-2011, 04:07 AM
So, how does one tell Mail to select a certain Smart Mailbox?

Less than ideal, but you can kind of cheat this with AppleScript. Say your Mailbox list looks like what is shown in the picture below. A script like this is a bit unorthodox, but it works (at least for me).

Basically, this uses AppleScript to select the Temp mailbox, move the focus to the Mailbox list (what's shown in the picture), simulate pressing an arrow key to move to the Smart Folder, then move the focus back to the list of messages (unseen but to the right in the picture).


tell application "Mail"
activate
set selected mailboxes of message viewer 1 to {mailbox "Temp" of account "The Hall"}
delay 0.75
tell application "System Events" to tell process "Mail"
--Let's move the focus from the messages to the Mailbox list by simulating a Shift-Tab press
key code 48 using shift down
--Arrow up here to get to the Smart Mailbox, use 125 if you need to move down
key code 126
--And let's move the focus back to the message list on the right
key code 48
end tell
end tell