Reply to topic  [ 6 posts ] 
Auto increment applescript to number paragraphs in BBEdit 
Author Message

Joined: 2010-03-12 00:37:07
Posts: 38
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!


2014-09-14 16:13:43
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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

_________________
philip


2014-09-14 17:51:30
Profile

Joined: 2010-03-12 00:37:07
Posts: 38
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!


2014-09-14 20:17:23
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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 171 times



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

_________________
philip


2014-09-14 21:52:43
Profile

Joined: 2010-03-12 00:37:07
Posts: 38
Thanks, phspaelti! It works perfectly!

:roll:


2014-09-15 00:23:50
Profile

Joined: 2010-03-12 00:37:07
Posts: 38
And frankly a Nisus Macro is a very nice thing to have! Somehow nicer than an AppleScript script!


2014-09-15 00:24:51
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: Bing [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software