Thursday, November 23, 2017

#1 2006-06-15 12:22:12 pm

johnnylundy
Member
Registered: 2003-11-18
Posts: 184

Setting the selected messages in Mail.app

Puzzled about this syntax problem: these two snippets work fine:

Applescript:


tell application "Mail"
   set x to selection
end tell

==> {
    message id 27754 of mailbox "INBOX" of account "JL@mac" of application "Mail"
}

Applescript:


tell application "Mail"
   set x to selected messages of first message viewer
end tell

==> {
    message id 27754 of mailbox "INBOX" of account "JL@mac" of application "Mail"
}

However, the next two, trying to set the selection to a particular message ID using the exact syntax returned by the above snippets, do not compile:

Applescript:


tell application "Mail"
   set selection to (message id 27754 of mailbox "INBOX" of account "JL@mac")
end tell

==> Applescript Syntax Error: Expected ", " but found number. ("27754" is highlighted)

Applescript:


tell application "Mail"
   set selected messages of first message viewer to (message id 27754 of mailbox "INBOX" of account "JL@mac")
end tell

==> Applescript Syntax Error: Expected ", " but found number. ("27754" is highlighted)

However, the following works just fine, setting the selection to null, and then back to what it was:

Applescript:


tell application "Mail"
   set x to selected messages of message viewer 1
   set selected messages of message viewer 1 to {}
   set selected messages of message viewer 1 to x
end tell

Anybody know what gives here? Why is the construct "message ID nnnnn of mailbox "INBOX" of account "JL@mac" " a syntax error, when that is what is returned from a "get selection"?


Filed under: mail

Offline

 

#2 2006-06-15 04:29:57 pm

Dominik
Member
Registered: 2006-02-09
Posts: 493

Re: Setting the selected messages in Mail.app

I think one problem might be that 'selected messages' expects a list - i found this one's working for example:

Applescript:


tell application "Mail"
   set selected messages of first message viewer to {first message of mailbox "INBOX" of account "JL@mac" whose id is 27754}
end tell


Filed under: mail

Offline

 

#3 2006-06-15 07:38:34 pm

johnnylundy
Member
Registered: 2003-11-18
Posts: 184

Re: Setting the selected messages in Mail.app

I know - if the where or whose clauses are used, then there is no syntax error. But when you ask for the selection, it returns the expression "message id xxxxx of mailbox "wwwww" of account "zzzzzz" ", yet using that exact syntax won't compile, even if you pass it as a list. For example:

Applescript:

message id 27754 of mailbox "INBOX" of account "JL@mac"

==> syntax error

or

Applescript:

{message id 27754 of mailbox "INBOX" of account "JL@mac"}

==> syntax error

or

Applescript:

(message id 27754 of mailbox "INBOX" of account "JL@mac") as list

==> syntax error

I don't think I ever saw a place where you HAD to use the where or whose construct to specify a record when you know the id and all the other properties. I came across this problem when trying to set the selection to a large list that I had generated of all messages that have attachments:

Applescript:


tell application "Mail"
   set theMasterList to {}
   repeat with theMailbox in inbox's mailboxes
       set theMessages to (messages of theMailbox whose mail attachments is not {})
       set theMasterList to theMasterList & theMessages
   end repeat
   tell message viewer 1
       set visible messages to theMasterList
       set selected messages to every message
   end tell
end tell

This works fine, setting the selection properly to only those messages with attachments.

It's still a mystery why "first message whose message id is 27754" compiles, but "message id 27754" does not compile.


Filed under: mail

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)