Auto increment applescript to number paragraphs in BBEdit

Get help using and writing Nisus Writer Pro macros.
Post Reply
jtranter
Posts: 38
Joined: 2010-03-12 00:37:07

Auto increment applescript to number paragraphs in BBEdit

Post by jtranter » 2014-09-14 16:13:43

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!

User avatar
phspaelti
Posts: 941
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Auto increment applescript to number paragraphs in BBEdi

Post by phspaelti » 2014-09-14 17:51:30

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
philip

jtranter
Posts: 38
Joined: 2010-03-12 00:37:07

Re: Auto increment applescript to number paragraphs in BBEdi

Post by jtranter » 2014-09-14 20:17:23

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!

User avatar
phspaelti
Posts: 941
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Auto increment applescript to number paragraphs in BBEdi

Post by phspaelti » 2014-09-14 21:52:43

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 193 times

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

jtranter
Posts: 38
Joined: 2010-03-12 00:37:07

Re: Auto increment applescript to number paragraphs in BBEdi

Post by jtranter » 2014-09-15 00:23:50

Thanks, phspaelti! It works perfectly!

:roll:

jtranter
Posts: 38
Joined: 2010-03-12 00:37:07

Re: Auto increment applescript to number paragraphs in BBEdi

Post by jtranter » 2014-09-15 00:24:51

And frankly a Nisus Macro is a very nice thing to have! Somehow nicer than an AppleScript script!

Post Reply