At 4:30 PM -0500 6/22/11, Christopher Stone sent email regarding Re: First Line of Selection?:
On Jun 22, 2011, at 10:52, Warren Michelsen wrote:
Now then, I seem to be having a problem using AS to select the first line of a document's selection. I've tried all kinds of things up to:

set my_line to paragraph 1 of the selection of text document 1 of text window 1
______________________________________________________________________

Hey Warren,

It appears that you want to 'get' rather than 'select' the first line of the selection.

Ummm..., once I've gotten it, where is it if I don't set something equal to it?


How does one set a variable to the first line of the selected text of the front-most BBEdit document window?


It's easy once you figure out which object to reference which is not always straightforward in Applescript. :)

 tell application "BBEdit"
   try
         tell text of front text window
           set my_line to line 1 of selection
         end tell

Seems strange telling something to the text. Very Object Oriented.


   on error errMsg number errNum
         set sep to "=============================="
         set e to sep & return & "Error: " & errMsg & return & sep & return ¬
           & "Error Number: " & errNum & return & sep
         beep
         display dialog e
   end try
 end tell

The new best practice with BBEdit is to reference the 'text of the front text window'.

Note that the code above will only provide a reference to the line object and not the contents thereof.

Noted.


 tell application "BBEdit"
   tell text of front text window
         set my_line to contents of line 1 of selection
   end tell
 end tell

Or as a one-liner:

tell application "BBEdit" to set my_line to contents of line 1 of selection of text of front text window

That's what I changed to from:

tell application "BBEdit"
        activate -- not taking any chances...
        select text window 1
        set the_text to the selection
        set my_line to line 1 of the_text as text
end tell


HTH.

It does.


--
Best Regards,
Chris

Back atcha.

--
You received this message because you are subscribed to the "BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

Reply via email to