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.

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

 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

Scope out:

 tell application "BBEdit"
   tell text of front text window
         properties of selection
   end tell
 end tell

If you *had* wanted to *select* the line:

 tell application "BBEdit"
   tell text of front text window
         select first line of selection
   end tell
 end tell

HTH.

--
Best Regards,
Chris

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