The BBEdit people kindly supplied me with a piece of AppleScript that auto-increments paragraph numbers in a document, where I have previously numbered all paragraphs with a caret: ^
The script changes the caret to 1, 2, 3, ...1,000, 1,001, 1,002, etc with no limit, sequentially incrementing the number by one each time.
Could Nisus provide a similar script? Here's the BBEdit one (the original has appropriate indents):
tell application "BBEdit"
activate
set i to 1
set continueSearch to true
select insertion point before line 1 of text window 1
repeat while continueSearch is true
set mySearch to find "^" searching in text 1 of text document 1 options {search mode:literal, wrap around:false} with selecting match
set continueSearch to found of mySearch
if continueSearch is true then
set selection to i as text
set i to i + 1
else
return
end if
end repeat
end tell
Thanks!
Auto increment applescript to number paragraphs in BBEdit
Re: Auto increment applescript to number paragraphs in BBEdi
Why would you want an applescript when you can have a Nisus macro?jtranter wrote:Could Nisus provide a similar script?

Code: Select all
# Number Paragraphs with Carets
$doc = Document.active
$text = $doc.text
$carets = $text.findAll '^\^', 'Ea'
$num = $carets.count
foreach $caret in reversed $carets
$numString = Cast To String $num
$numString.replaceAll '\d{3}$', ',\0', 'E'
$text.replaceInRange $caret.range, $numString
$num -=1
end
philip
Re: Auto increment applescript to number paragraphs in BBEdi
Thanks, kindly, phspaelti, but I tried to run your macro and received this message:
There was an error on line 1 in the macro "Number Paragraphs with Carets".
Unknown menu item path:
http://nisus.com/forum/posting.php?mode ... =17&t=5831#
Maybe I place the macro in the wrong place. But thanks!
There was an error on line 1 in the macro "Number Paragraphs with Carets".
Unknown menu item path:
http://nisus.com/forum/posting.php?mode ... =17&t=5831#
Maybe I place the macro in the wrong place. But thanks!
Re: Auto increment applescript to number paragraphs in BBEdi
The above is macro code and would need to either be saved into a Nisus Macro file, or if it is in a regular file you could run it by selecting it and using "Run Selection as Macro"
Anyhow here is the macro version:
As for the error message, maybe you copied the code with the text "Code:", or without the "#"?
Anyhow here is the macro version:
As for the error message, maybe you copied the code with the text "Code:", or without the "#"?
philip
Re: Auto increment applescript to number paragraphs in BBEdi
Thanks, phspaelti! It works perfectly!


Re: Auto increment applescript to number paragraphs in BBEdi
And frankly a Nisus Macro is a very nice thing to have! Somehow nicer than an AppleScript script!