counting with bbedit

Hi,

I am trying to set up a search that looks for a series of quark xpress tags and numbers them such as in a numbered list. In my test file I have my applescript searching for T and S and then numbering all the M’s in that selection a certain number. My next search looks for those numbers and then renumbers each group. Below is my test file example:

T
M
M
M
S
T
M
M
M
M
M
S

When I run my script it looks like this:

T
01
02
03
S
T
0002
0002
0002
0002
0002
S

I think I don’t have the counter for the second part of my script in the right place, but I’m not sure what else to try. Any help would be greatly appreciated. Below is my applescript as it stands:

tell application “BBEdit”
activate
–does selection search for T and S and then numbers M
try
select insertion point before character 1 of text window 1
set stepper to 1
set stillfinding to true
repeat while stillfinding
set stillfinding to find “T” searching in text of text window 1 options {search mode:literal, starting at top:false, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false} with selecting match
set stillfinding to the found of stillfinding
if (stillfinding) then
find “S” searching in text 1 of text window 1 options {search mode:literal, starting at top:false, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:true} with selecting match
set padding to (10000 + stepper) as text
replace “M” using “” & (character 2 of padding) & (character 3 of padding) & (character 4 of padding) & (character 5 of padding) & “” searching in selection of text window 1 options {search mode:literal, starting at top:false, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
set stepper to stepper + 1
end if
end repeat
end try

--searches for number generated by previous search and number incremently
try
	set counter to 1
	set stepper to 1
	set stillfinding2 to true
	set stillfinding to true
	select insertion point before line 1 of window 1
	
	repeat while stillfinding
		set spacing to (10000 + counter) as text
		set stillfinding to find "" & (character 2 of spacing) & (character 3 of spacing) & (character 4 of spacing) & (character 5 of spacing) & "" searching in text of text window 1 options {search mode:literal, starting at top:false, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false} with selecting match
		set stillfinding to the found of stillfinding
		if (stillfinding) then
			set padding to (100 + stepper) as text
			set selection to "" & (character 2 of padding) & (character 3 of padding) & ""
			set stepper to stepper + 1
		end if
		
	end repeat
	set counter to counter + 1
end try

display dialog "The search is complete" buttons "OK" default button 1 with icon 1

end tell

What do you want the final text to look like?

Jon

Hi,

The result should look like the following:

T
01
02
03
S
T
01
02
03
04
05
S

Thanks,
Jon

You need one more repeat loop with a test to see if looking for a list fails twice. This should work:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

That worked awesome. Thanks for the help