Initial conditions:
BBEdit 11.6.8
macOS 10.12.6 Sierra
AppleScript 2.5 with Script Editor 2.9

As part of my overall project, i have a small temporary text file where 
i’ve collected my story chapter titles. At this stage of things, this file 
is partly processed, related to earlier steps—which all work great. This is 
the step where i finish processing it to syntactically-correct HTML, in 
preparation for selecting all of it and copy/pasting into (an ordered list 
in) another document.

A sample file is attached, for anyone who may wish to test/help. It’s short 
enough that i can also paste it here:

1Quite An Introduction</a></li>
2Moving the Plot Forward</a></li>
3Things Get Messy</a></li>
4Life Is Better</a></li>
5Adulting Sucks!</a></li>
6Aging Is Worse</a></li>
7Let’s Not Talk About Late Life</a></li>
8Epilog</a></li>

My traditional workflow has the following Grep Find/Replace:
Grep Find, wrap around:
(\d\d?)(.+?)</a>

Replace:
<li><a href="ExampleStoryC\1.html" title="Example Story chapter \1: 
\2">\2</a>

The end result should look like this (other than without the empty lines 
between each <li> line):

<li><a href="ExampleStoryC1.html" title="Example Story chapter 1: Quite An 
Introduction">Quite An Introduction</a></li>

<li><a href="ExampleStoryC2.html" title="Example Story chapter 2: Moving 
the Plot Forward">Moving the Plot Forward</a></li>

<li><a href="ExampleStoryC3.html" title="Example Story chapter 3: Things 
Get Messy">Things Get Messy</a></li>

<li><a href="ExampleStoryC4.html" title="Example Story chapter 4: Life Is 
Better">Life Is Better</a></li>

<li><a href="ExampleStoryC5.html" title="Example Story chapter 5: Adulting 
Sucks!">Adulting Sucks!</a></li>

<li><a href="ExampleStoryC6.html" title="Example Story chapter 6: Aging Is 
Worse">Aging Is Worse</a></li>

<li><a href="ExampleStoryC7.html" title="Example Story chapter 7: Let’s Not 
Talk About Late Life">Let’s Not Talk About Late Life</a></li>

<li><a href="ExampleStoryC8.html" title="Example Story chapter 8: 
Epilog">Epilog</a></li>

This works perfectly, done manually. I’m trying to script the same thing. 
Here is my test script:

*set* StoryTitle *to* "Example Story"

*set* ConcatStoryTitle *to* "ExampleStory"

-- In reality, ^those titles^ are set and used much earlier in the much 
longer overall script


*tell* *application* "BBEdit"

*tell* *text document* 1

*replace* "(\\d\\d?)(.+?)</a>" using "<li><a href=\"" & ConcatStoryTitle & 
"C" & (*grep substitution* of ("\\1" *as* *text*)) & ".html\" " & 
"title=\"" & StoryTitle & " chapter " & (*grep substitution* of ("\\1" *as* 
*text*)) & ": " & (*grep substitution* of ("\\2" *as* *text*)) & "\">" & (*grep 
substitution* of ("\\2" *as* *text*)) & "</a>" options {search mode:*grep*, 
wrap around:*true*}

*end* *tell*

*end* *tell*


When i run the script, the Events look like this:

*tell* *application* "BBEdit"

*grep substitution* of "\\1"

*Result:*

*error* "BBEdit got an error: The replacement string couldn’t be computed, 
because the previous Grep search did not succeed (application error code: 
12003)" number 12003


I haven’t been able to figure out what i’m doing wrong. Looking forward to 
learning something else new about scripting BBEdit.

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "[email protected]" rather than 
posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/14bc3311-a321-4c8c-9a56-1a1703b2e89dn%40googlegroups.com.
1Quite An Introduction</a></li>
2Moving the Plot Forward</a></li>
3Things Get Messy</a></li>
4Life Is Better</a></li>
5Adulting Sucks!</a></li>
6Aging Is Worse</a></li>
7Let’s Not Talk About Late Life</a></li>
8Epilog</a></li>

Reply via email to