• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: myLoop: getting subject of messages in Mail.app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: myLoop: getting subject of messages in Mail.app


  • Subject: Re: myLoop: getting subject of messages in Mail.app
  • From: Christopher Nebel <email@hidden>
  • Date: Mon, 3 Mar 2003 18:31:44 -0800

At 7:01 pm -0600 28/2/03, Phebe Anggreani wrote:

I'm trying to set focused on thread of selected message. But somehow it always returned an error when repeating to get the subject of message x....

tell application "Mail"
repeat with thisMsg in all messages of front message viewer
(*here's where the problem begins, I can't get the subject of the message*)
if subject of thisMsg contains (mainSbj as string)...

The problem has to do with how AppleScript handles repeat loops of this form. Mail exacerbated the problem by using an "all messages" property that returns a list; if they had used an element relationship, it would have worked. (Well, as of Jaguar -- Cocoa Scripting used to not handle that correctly.) You can see the same problem with the Finder's "selection" property -- try asking for "item 1 of the selection".

When you write a repeat loop like this, the loop variable ("thisMsg", here) doesn't get set to an actual message. Instead, it's "item 1 of all messages of front message viewer", then item 2, and so on. (Yes, this is the same thing behind the infamous repeat problem in AppleScript itself.) Mail doesn't know how to handle getting an element of a property like this, and falls over.

By hoisting "all messages of front message viewer" out of the loop, you force it to be evaluated into an AppleScript list, which *can* handle the "item 1 of ..." request correctly, so it works.

The upshot of this is that there are two bugs:

1. AppleScript handles "repeat with i in x" loops in an interesting way that makes it difficult for applications (and scripters) to do the right thing. This is "working" as designed, and won't be fixed any time soon.

2. Mail should define "message" as an element of "message viewer", instead of having a collective "all messages" property, which would let you do a number of other interesting things as well. cricket makes the call on that.


--Chris Nebel
AppleScript Engineering
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: myLoop: getting subject of messages in Mail.app
      • From: Paul Skinner <email@hidden>
    • Re: myLoop: getting subject of messages in Mail.app
      • From: cricket <email@hidden>
References: 
 >Re: myLoop: getting subject of messages in Mail.app (From: John Delacour <email@hidden>)

  • Prev by Date: Re: myLoop: getting subject of messages in Mail.app
  • Next by Date: Re: myLoop: getting subject of messages in Mail.app
  • Previous by thread: Re: myLoop: getting subject of messages in Mail.app
  • Next by thread: Re: myLoop: getting subject of messages in Mail.app
  • Index(es):
    • Date
    • Thread