• 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: Paul Skinner <email@hidden>
  • Date: Tue, 4 Mar 2003 00:08:14 -0500

On Monday, March 3, 2003, at 09:31 PM, Christopher Nebel wrote:

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".

ASLG on p. 256 makes it appear that AS will happily make this easy for the user...

repeat with loopVariable in list
[ statement ]...
end [ repeat ]
where
loopVariable is any previously defined variable or a new variable you define in the Repeat statement (see Notes).
list is a list or a reference (such as words 1 thru 5) whose value is a list.
list can also be a record; AppleScript coerces the record to a list (see Notes).
statement is any AppleScript statement.
...
set wordList to words in "Where is the hammer?"
repeat with currentWord in wordList
--log currentWord
if currentWord as text is equal to "hammer" then
display dialog "I found the hammer!"
end if
end repeat

Perhaps this should be revised to include a note that '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' ;)

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

Damn straight. And I'm glad to see that he agrees.
This kind of basic information should be presented to each team, early on, by the AS team. And the implementation should be reviewed by the AS team prior to new releases. IMHO.
I also would really like to see Apple bring Cal back to watch over this stuff, but, I don't think that's going to happen. If they did, he would flip out over some of the current implementations.

I have got to say that, in the short time that I tested this thread in Mail.app, I was shocked!

tell application "Mail"
set msgs to get all messages of front message viewer--Trying to do the 'right' thing.
repeat with thisMessage in msgs
sender of thisMessage -->sender
subject of thisMessage -->Subject
--ect... But!
properties of thisMessage -->{}
end repeat
end tell

I can't get something's properties as a list then I, well I just stop right there and say a curse. Why bother going any further. I'm actually a little frightened to look further, I have a bad habit of trying to figure out why this doesn't work and why I can't get this to do that etc. I could get stuck in there for weeks!

Paul Skinner
_______________________________________________
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.
References: 
 >Re: myLoop: getting subject of messages in Mail.app (From: Christopher Nebel <email@hidden>)

  • Prev by Date: replacing text
  • Next by Date: Date formatting
  • 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