Re: mail.app: can't get selection
Re: mail.app: can't get selection
- Subject: Re: mail.app: can't get selection
- From: "Gary (Lists)" <email@hidden>
- Date: Sat, 04 Jun 2005 22:26:08 -0400
"Paul Berkowitz" wrote:
> On 6/4/05 6:20 PM, "tim" <email@hidden> wrote:
>
>> Hi, I've been trying to write a script to rewrite the source of an email in
>> mail.app
>>
>> I keep getting stumped at just trying to get the message I have selected
>>
>> 1. I f i say "tell application return selection" i get a list containing
>> (apparently) a meesage reference but i can't say "get item 1 of selection" :
>> this returns the error can't make reference. Also can't access any property
>> of any item of what should be a list of selected messages.
>>
>> Any clues on this?
>>
>> Secondly, this script just seems wierd: how can p not be defined when it has
>> been iterated over?
>>
>> tell application "Mail"
>> repeat with anitem in selection --two messages selected
>> set p to anitem
>> end repeat
>> return p
>>
>> --applescript error the variable p is not defined
Paul and Tim, I get quite different results from what you each report.
Perhaps I am using an older version of both the Mail.app and AS?
(Mail 1.3.11 v622 / OS X.3.9 / AS 1.9.3)
Tim's first version produces:
tell application "Mail"
repeat with anitem in selection -- two msgs
set p to anitem
end repeat
return p
end tell
-- item 2 of selection of application "Mail"
Which is of the "weird reference format" variety. (Continued below.)
But no error regarding 'p'.
> Try
>
> (get selection)
>
> That one is pretty common, for 'selection' property of an application, in many
> apps (including Entourage, which you know well).
>
> And if you want to force an error anywhere in any of the weirdo iApps, you
> have to
>
> get someVariable -- get p
>
> immediately after defining the variable. Otherwise it won't error until you
> next try to use the variable it doesn't error when you first define it.
>
> This works:
>
> tell application "Mail"
> repeat with anitem in (get selection)
> set p to anitem
> end repeat
> return p
> end tell
>
> but gets you that weird reference format
>
> --> item 3 of {
> message id 5719 of mailbox "INBOX" of account "email@hidden",
> message id 5720 of mailbox "INBOX" of account "email@hidden",
> message id 5721 of mailbox "INBOX" of account "email@hidden" }
Using 'get selection', I get the exact form of the "weird reference format",
but sans any kind of message id.
tell application "Mail"
repeat with anitem in (get selection)
set p to anitem
end repeat
return p
end tell
-- item 2 of {message 4 of mailbox "Drafts" of account "Testing" of
application "Mail", message 5 of mailbox "Drafts" of account "Testing" of
application "Mail"}
Continuing...
> So this is better:
>
> tell application "Mail"
> repeat with anitem in (get selection)
> set p to anitem
> end repeat
> return contents of p
> end tell
> --> message id 5721 of mailbox "INBOX" of account "email@hidden"
tell application "Mail"
repeat with anitem in (get selection)
set p to anitem
end repeat
set mrc to contents of p
end tell
-- message 5 of mailbox "Drafts" of account "Testing" of application
"Mail"
As you see, I get a more useful reference, but still no message ID.
However, Tim wanted to get to the 'source' of the message, and this does
work for me:
tell application "Mail"
repeat with anitem in (get selection)
set p to anitem
end repeat
set mrc to contents of p
end tell
return mrc
-- "Hello, world."
But, of course, this looping and such only returns the last message, so I'm
not sure what the intent was ... to capture the source of multiple messages?
Then the logic should be inside the loop.
(Or did I miss something ... twice ...?)
--
Gary
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden