nisus.com
https://www.nisus.com/forum/

Auto increment applescript to number paragraphs in BBEdit
https://www.nisus.com/forum/viewtopic.php?f=17&t=5831
Page 1 of 1

Author:  jtranter [ 2014-09-14 16:13:43 ]
Post subject:  Auto increment applescript to number paragraphs in BBEdit

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!

Author:  phspaelti [ 2014-09-14 17:51:30 ]
Post subject:  Re: Auto increment applescript to number paragraphs in BBEdi

jtranter wrote:
Could Nisus provide a similar script?

Why would you want an applescript when you can have a Nisus macro? :)

Code:
# 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

Author:  jtranter [ 2014-09-14 20:17:23 ]
Post subject:  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:


posting.php?mode=reply&f=17&t=5831#
Maybe I place the macro in the wrong place. But thanks!

Author:  phspaelti [ 2014-09-14 21:52:43 ]
Post subject:  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:
Attachment:
Number Paragraphs with Carets.nwm [3.94 KiB]
Downloaded 170 times



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

Author:  jtranter [ 2014-09-15 00:23:50 ]
Post subject:  Re: Auto increment applescript to number paragraphs in BBEdi

Thanks, phspaelti! It works perfectly!

:roll:

Author:  jtranter [ 2014-09-15 00:24:51 ]
Post subject:  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!

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/