Page 1 of 1

Auto increment applescript to number paragraphs in BBEdit

Posted: 2014-09-14 16:13:43
by jtranter
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!

Re: Auto increment applescript to number paragraphs in BBEdi

Posted: 2014-09-14 17:51:30
by phspaelti
jtranter wrote:Could Nisus provide a similar script?
Why would you want an applescript when you can have a Nisus macro? :)

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

Re: Auto increment applescript to number paragraphs in BBEdi

Posted: 2014-09-14 20:17:23
by jtranter
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!

Re: Auto increment applescript to number paragraphs in BBEdi

Posted: 2014-09-14 21:52:43
by phspaelti
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:
Number Paragraphs with Carets.nwm
(3.94 KiB) Downloaded 175 times

As for the error message, maybe you copied the code with the text "Code:", or without the "#"?

Re: Auto increment applescript to number paragraphs in BBEdi

Posted: 2014-09-15 00:23:50
by jtranter
Thanks, phspaelti! It works perfectly!

:roll:

Re: Auto increment applescript to number paragraphs in BBEdi

Posted: 2014-09-15 00:24:51
by jtranter
And frankly a Nisus Macro is a very nice thing to have! Somehow nicer than an AppleScript script!