Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

With the help of "Ask Different" I got my first AppleScript program working, and I'm trying to improve it. I'm again stymied though.

I have found the message number ID of a particular message in my account's INBOX. AppleScript tells me it is ID 167868. I hope that sounds reasonable, as I have only about 190 messages in my INBOX. I'm assuming that the id specifies exactly which message is concerned.

Now I want to activate Mail, select the INBOX of my account, sort the messages according to the "From:" field and select the message with that id. After that I want to use Mail interactively.

I've been trying to find out how to do this from various AppleScript manuals, but it's all a bit uphill for a beginner, and I would appreciate some help. I tried looking through some AppleScript dictionaries for Mail.app, but I couldn't find appropriate commands, except for "activate". I saw various things in sample code like "menu bar 1", but didn't know how to find the menu items in menu bar 1.

Sorry to ask elementary questions, but I need to get a program working, and this should be only a couple of lines away. After that, I'll be motivated to work more slowly and systematically through some tutorials, so that the level of my questions improves.

share|improve this question
    
You should read about System Events and UI Elements. So you don't have to navigate the elements programatically, UI Browser provides a nice interface to expose the hierarchy. –  adayzdone Nov 24 '13 at 14:40

1 Answer 1

Probably not the only way to do it... And these are not my favourite type of scripts.

But here is an example of each of the syntax you describe.

Look up:

  • message viewer
  • selected mailboxes
  • selected messages

In the Applescript library for Mail.

tell application "Mail"
    set theMailID to 543521
    set theM to mailbox "INBOX" of account "iCloud"

    set selected mailboxes of message viewer 1 to theM
    set sort column of message viewer 1 to from column
    delay 0.5 -- important delay or message selection may not happen
    set selected messages of message viewer 1 to (first message of (theM) whose id = theMailID)

end tell
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.