I’ve been using BBEdit for many years now, but have never scripted it. Looking at it’s dictionary, I find an embarrassment of riches - many suites, and the usual difficulties of understanding their terms. What I want to do is “inhale” a selection on a page, add AppleScript tags to the beginning and end, and then replace the selection. The dictionary says I can set a selection, but apparently you cannot set its contents, so this simple script doesn’t work (where the last line compiles, but errors on execution):
property AS_start : "[|applescript|]" & return -- pipes added so the bbs won't interpret the tags
property AS_end : "[|/applescript|]" & return
tell application "BBEdit" to set S to contents of selection of window 1
set contents of selection of window 1 to AS_start & S & AS_end -- compiles, but fails.