Hey Christopher,

The code you gave works very well. However, when integrated with my own 
instructions, AppleScript crashes! I don't understand why. So I wrote a 
substitution routine.

set count_comments to replaceTokensWithGrep("^'[\\S\\t ]*\\r", nullStr)

replaceTokensWithGrep(textToSearch, replaceWith) just do a replace all.

AppleScript is not really a friend of regex ;-) You have to test the text 
to transform with BBEdit and then translate it into AppleScript string to 
incorporate it into the script. 

And sometimes it doesn't work, for example with \x20{6} supposed to replace 
six spaces. Is there a way to enter in AppleScript the same plain text used 
in BBEdit, with a tell statement for exemple ?

Best Regards,
Lionel

Le mercredi 21 septembre 2022 à 17:19:07 UTC+2, [email protected] a 
écrit :

> On Sep 20, 2022, at 10:46, Lionel <[email protected]> wrote:
>
>
> A call to the AppleScript library of BBEdit sometimes returns the number 
> of hits found, this is the case with replace.
>
> process lines containing text 1 of text document 1 matching string "^'" 
> output options {deleting matched lines:true} with matching with grep
>
> But with "process lines containing text" for example, this is not the case 
> and it is better to avoid testing the returned value. It must be somewhere 
> but not in the global property « result ». If someone has a solution, I'm 
> interested.
>
> ------------------------------
>
> Hey Lionel,
>
> BBEdit's *process lines containing* command does *not* return the number 
> of processed lines - period.
>
> You have to look at the actual output of the command.  When you do you 
> find it returns a record containing two items:
>
> modified text
> copied lines
>
> *Modified text* is what the text in your document is transformed into by 
> the command, and *copied lines* is the lines that are deleted.
>
> What's more – *copied lines* is always punctuated with a linefeed – even 
> when the last line deleted doesn't have one.
>
> So – you have to do something like this:
>
> --------------------------------------------------------
> # Auth: Christopher Stone
> # dCre: 2022/09/21 10:00
> # dMod: 2022/09/21 10:00 
> # Appl: BBEdit
> # Task: Return the Number of Processed Lines.
> # Libs: None
> # Osax: None
> # Tags: @Applescript, @Script, @BBEdit, @Processed, @Lines, 
> @Processed_Lines
> --------------------------------------------------------
>
> *tell* *application* "BBEdit"
> *tell* *front* *text window's* *text*
> *set* processLinesResultRecord *to* *process lines containing* matching 
> string "^[ts]" output options {deleting matched lines:*true*} *with* matching 
> with grep
> *end* *tell*
>
>
> *set* numberOfProcessedLines *to* copied lines *of* 
> processLinesResultRecord
>
>
> *if* numberOfProcessedLines ≠ "" *then*
> # Remove the extraneous linefeed at the end of 'copied lines'.
> *set* numberOfProcessedLines *to* *replace* "\\s\\z" using "" 
> searchingString numberOfProcessedLines options {search mode:*grep*}
> # Count the number of paragraphs to determine the number of processed 
> lines.
> *set* numberOfProcessedLines *to* length *of* (*get* *paragraphs* *of* 
> numberOfProcessedLines)
> *end* *if*
>
>
> *end* *tell*
>
> --------------------------------------------------------
>
> You could simply subtract 1 from the number of paragraphs instead of 
> munging the string as I have.
>
> I'm using BBEdit 14.1.2 on macOS 10.14.6 for this test.  I doubt the 
> newest version has changed much in this regard but can't be certain.
>
> --
> Best Regards,
> Chris
>
>

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "[email protected]" rather than 
posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/3760f14e-34b7-4c21-832e-f97d4a19e671n%40googlegroups.com.

Reply via email to