Re: get selected text of message in Mail?
Re: get selected text of message in Mail?
- Subject: Re: get selected text of message in Mail?
- From: "Gary (Lists)" <email@hidden>
- Date: Fri, 02 Sep 2005 05:03:37 -0400
Charles Arthur wrote:
>>>>
>>>> OK, I can't figure it out. Is it feasible?
>>>>
>>>> In Eudora (where yes, I enjoy changing the subject line... oh, that's
>>>> another topic, isn't it?) one can do
>>>>
>>>> set thetext to selected text
>>>>
>>>> and get, well, the text you've selected in whatever message you're
>>>> looking at.
>>>>
>>>> However I've found nothing comparable in Mail.
>>>>
>>>> [snip]
>>>>
>>>> Any way to do this?
Matt Neuburg wrote:
>>>
>>> No. m.
"Kai" wrote:
>>
>> It seems that Mail (along with a crop of other Cocoa apps) doesn't
>> yet have this capability, Charles. Hopefully, there are plans to add
>> it at some point. In the meantime, I'm using a kludge:
>>
>> ---------------
>>
>> on selectedText from p (* Mail, Safari, TextEdit, Address Book, etc. *)
>> tell application p to activate
>> tell application "System Events" to tell menu item "Copy" of
>> menu "Edit" of ¬
>> menu bar item "Edit" of menu bar 1 of process p to if
>> enabled then
>> tell application p to set c to the clipboard (* store
>> current clipboard *)
>> click
>> delay 0.4 (* allow time to copy: adjust as required *)
>> tell application p
>> if (count (clipboard info for string)) is 0 then
>> set s to ""
>> else
>> set s to the clipboard as string
>> end if
>> set the clipboard to c (* restore previous clipboard *)
>> return s
>> end tell
>> end if
>> ""
>> end selectedText
>>
>> selectedText from "Mail"
>>
>> ---------------
"Martin Orpen" wrote:
>
> How about:
>
> activate application "Mail"
> tell application "System Events"
> tell process "Mail"
> get value of attribute "AXSelectedText" of text area 1 of scroll
> area 2 of splitter group 1 of window 1
> end tell
> end tell
>
>
> Works for me in Tiger :)
Works for me in Panther. Good stuff, Kai and Martin.
Well, I liked the "preserve the original clipboard" politeness in Kai's
script, and obviously Martin's is shorter and speedy.
I've been using one of the alternate OSX pasteboards to preserve the
original clipboard in my scripts, so I'll combine that method with Martin's
script and with Kai's politeness.
How about a 2-line, original preserving, version.
This 2-liner works to get the selection and preserve the original board OMM
(Panther X.3.9) in Mail and in TextEdit, but not Safari, for example.
-- -----
set myClip0 to the clipboard
-- ----- actual work
tell application "System Events" to tell process "TextEdit" to do shell
script "echo " & (get value of attribute "AXSelectedText" of text area 1 of
scroll area 1 of window 1) & " | pbcopy -pboard find" -- line 1
set mySelect to do shell script "pbpaste -pboard find" -- line 2
-- -----
{myClip0, mySelect}
-- -----
There's no need to have the first line 'set myClip0', but I just include it
for demo purposes.
I don't know if folks want to trash the 'find' pasteboard in circulated
scripts, but I've been using it like this locally, because it kind of makes
logical sense that the 'find' pasteboard would be even more "volatile" than
other pasteboards.
--
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