I can't figure out why this AppleScript is not working. I'm trying to do the 
following:

Starting with a selection of multiple lines, beginning at a line start and 
ending with a return, I want to:

(1) shift the selection one increment to the right;

(2) add an opening div tag before it, preceded but the number of tabs that 
preceded the first line of the selection before the shift;

(3) add a closing dive tag after it, similarly tabbed.

The script runs fine, and returns what I would expect, until the last action, 
the Replace line. But the replacement replaces all the text with two garbage 
characters.

Several variants for addressing the target string are listed, but it's not 
working either way.

Here's the script. Any help -- or an easier approach -- is welcome. Thanks.

Rick Gordon

--------

set vOpeningTag to "<div class=\"keep\">" & return
set vClosingTag to "</div>" & return

tell application "BBEdit 10"
  set vSelection to selection

  tell vSelection
    set vTabLeader to (find "^  +" options {search mode:grep, showing 
results:false} searching in contents)
    shift direction right
  end tell

  set vSelection to selection

  tell vSelection
    set vStart to characterOffset
    set vEnd to characterOffset + length
  end tell

  set vOpeningTag to vTabLeader & vOpeningTag
  set vClosingTag to vTabLeader & vClosingTag
 
 tell document 1
    set vTarget to a reference to characters vStart thru vEnd
    -- OR set vTarget to characters vStart thru vEnd

    tell contents of vTarget
   -- OR  tell vTarget
      replace "(?s)(.+)" using vOpeningTag & "\\1" & vClosingTag options 
{search mode:grep, showing results:false, extend selection:true}
    end tell
  end tell
end tell

-- 
___________________________________________________

RICK GORDON
EMERALD VALLEY GRAPHICS AND CONSULTING
___________________________________________________

WWW:   http://www.shelterpub.com

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