Re: Text Factory Equivalent for BBEdit: Text: Remove Line Breaks?

2023-05-24 Thread Christopher Stone
> On May 24, 2023, at 07:16, Mark Mayberry  wrote:
> 
> However, I cannot figure out which Text Factory command is the equivalent of 
> simply pressing  BBEdit Text (Menu) >> Remove Line Breaks.

Hey Mark,

Surprisingly there isn't one...

You have to roll-your-own via a RegEx, AppleScript-filter, or text-filter.

I tend to turn to AppleScript for this sort of thing.

Note how you can mix and match AppleScript and Text Factories. In this instance 
it's easy enough to employ BBEdit's own 'remove line breaks' command.

Glad you're enjoying the Mac and BBEdit ( and Keyboard Maestro :).

-Chris


----
# Auth: Christopher Stone 
# dCre: 2023/05/24 18:30
# dMod: 2023/05/24 18:30 
# Appl: BBEdit, System Events
# Task: Run a Specific Text Factory and ‘remove line breaks’ on the Front 
Document.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @System_Events, @Text-Factory, 
@Remove_Line_Breaks


set textFactoryFile to "~/Library/Application Support/BBEdit/Text Filters/Text 
Factories/TEST.textfactory"
tell application "System Events" to set textFactoryFile to (POSIX path of disk 
item textFactoryFile)

tell application "BBEdit"
set frontDoc to front text document
apply text factory textFactoryFile to frontDoc
tell frontDoc's text
remove line breaks
end tell
end tell



-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/72A11FB2-C6FC-4D56-9431-B5DC03DCEBAE%40gmail.com.


Re: Find and Replace items which do NOT contain a simple pattern...

2023-05-14 Thread Christopher Stone
> On May 14, 2023, at 11:29, 'Andy Nickless' via BBEdit Talk 
> mailto:bbedit@googlegroups.com>> wrote:
> 
> Something that I've been unable to find out is how to skip searching 
> something which already contains a simple pattern:
> For instance, to find a number consisting 1-3 digits I use (\d{1,3}) - but 
> how can I AVOID a number of up to 3 digits?

Hey Andy,

It's really necessary to provide proper examples when asking for help with 
regular expressions...

One needs to be able to visualize and test with real-world data to be able to 
untangle this sort of problem properly.

I can't think of a way using only regex to avoid all of the possible pitfalls – 
this example using a negative-lookahead will match only the lines in the middle 
block.


__PATTERN__

(?>(?:(?!|\d{1,3}).)*)

___TEST DATA___

1
10
100
2000
2

Thank you India
Thank you terror
Thank you disillusionment

Thank you frailty 1
Thank you consequence 22
Thank you thank you silence 33


The only way I can think of to manage this puzzle in a bombproof way is to 
script it, and I'd probably use Perl for that.

--
Take Care,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/B81B9D59-5DF4-4EB8-8DDF-1E02A2DEFB54%40gmail.com.


Re: Include file name in grep/extract results?

2023-05-10 Thread Christopher Stone
> On May 07, 2023, at 14:17, severdia  wrote:
> 
> I have a lot of XML files and I'd like to grep a string and use Extract to 
> copy that string from each file to a single CSV file. Is there a pattern for 
> including the filename the strong was extracted from in the results? My goal 
> is a single text file (comma separated) that contains the string found from 
> each XML file.

Hey Severdia,

I'm not aware of any tokens that can return the file name or path during a 
multi-file search...

However – to get what you need you can:
Do a multi-file search (Cmd-Shift-F).
Copy the contents of the search results window.
Paste that into a new document.
Do a little post-processing.
--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/C62B03EE-BB72-470E-A9CA-6140515996F1%40gmail.com.


Re: How to show number of corrections in bbedit?

2023-04-24 Thread Christopher Stone
> On Apr 24, 2023, at 13:04, Omar KN  wrote:
> 
> This was already asked some years ago, now after migrating to a new computer 
> - - 
> 
> when doing any FIND & "replace" action, where is the setting which allows the 
> users to see the number of corrections/replacements?

Hey Omar,

Save this URL:

https://www.barebones.com/support/bbedit/ExpertPreferences.html


When performing a single-file "Replace All" operation, BBEdit can show a 
confirmation sheet showing the number of replacements performed. If you would 
like to see this confirmation:

defaults write com.barebones.bbedit ReportReplaceAllResults -bool YES


--
Take Care,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/0F54794F-CABF-4AEF-B9C0-42B4FA6801DD%40gmail.com.


Re: Capturing multiple variables in regular expression

2023-03-22 Thread Christopher Stone
> On Mar 22, 2023, at 10:40, Doug Pinkerton  wrote:
> 
> I need to convert data formatted for humans into data formatted for a 
> database. The actual document is subject to privacy regulation. The following 
> is a mockup to illustrate the task. I need to convert this:


Hey Doug,

Here's a Perl filter that will do the job.

-Chris

#!/usr/bin/env perl -0777 -nsw
# ----
# Auth: Christopher Stone
# dCre: 2023/03/22 16:51
# dMod: 2023/03/22 16:51
# Task: Reformat Data for Use in a Database.
# Tags: @ccstone, @Shell, @Script, @Reformat, @Data, @Database
# 
use v5.12;

$_ =~ s!\A\s+|\s+\Z!!g;

my @recordArray = split(/\n\n/, $_);

foreach my $record (@recordArray) {
my @record = split(/\n/, $record);
my $line1 = $record[0];
$line1 =~ s!^(.+)\h?-.+!$1!;
my $line2 = $record[1];
$line2 =~ s!^(\w+)\h.+!$1!;
my $prefix = $line1 . "\t" . $line2;
my $recordLength = scalar(@record) - 1;
my @newRecord = @record[2 .. $recordLength];

foreach my $recordItem (@newRecord) {
say $prefix . "\t" . $recordItem;
}

}

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/7DAFE8F0-A39B-4593-A7D6-E1491F03B680%40gmail.com.


Re: Need help simplifying apple script with grep

2023-03-20 Thread Christopher Stone
On Mar 19, 2023, at 15:17, Mathias  wrote:
> OK folks, I feel like I'm nearly there, but I have a small outstanding issue 
> that perhaps you can find it in your heart to help me with.


Hey Mathias,

What about something like this?

("[^"]+?") = "(.+?)";


-Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/4FBED81C-7C28-4652-8963-B9533A3A21D3%40gmail.com.


Re: Need help simplifying apple script with grep

2023-03-18 Thread Christopher Stone
On Mar 17, 2023, at 09:29, Bruce Van Allen  wrote:
> Yes, double escapes are needed. As handy as Applescript is, quoting is a 
> major pain point.


Not if you use Script Debugger .

SD has a “Paste as String Literal” command that automates the double-quoting as 
necessary.

I don't know for certain if the freeware "lite" version has this command, but I 
think it likely – since it's not listed in the feature comparison chart:

https://latenightsw.com/sd8/feature-comparison/

To go the other direction you can display the string in a result-viewer and 
select “Best View” and copy – or you can just set the clipboard to the string.

With just a little set-up this issue is trivial to manage.

-Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/08426B1C-3690-4A1D-A8E8-2B00412BFC68%40gmail.com.


Re: Scripting a Find, then doing a second Find, searching in the first Find's results

2023-02-17 Thread Christopher Stone
> On Feb 17, 2023, at 12:38, Bruce Van Allen  wrote:
> Only happened because I always study your great scripts to learn from them!


Whups I just realized I only tested with lines that would match the find 
criteria, so other lines would be excluded.

Here's the fix for that.

#!/usr/bin/env perl -sw
# --
# Auth: Christopher Stone
# dCre: 2012/11/27 08:12
# dMod: 2023/02/17 12:43
# Task: Encode Spaces in Text Selection for a Given Pattern.
# Tags: @ccstone, @Shell, @Script, @Encode, @Spaces, @RegEx
# Vers: 2.00
# --
use v5.010;

while (<>) {
   if ( m!(.+)()(.+)! ) {
  my $prefixStr  = $1;
  my $newSubject = $2;
  my $suffixStr  = $3;

  $newSubject =~ s!\h!%20!g;
  say $prefixStr . $newSubject . $suffixStr;
  
   } else {

  print;
  
   }
}

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/9E842A8E-9CDE-4389-8152-7100D945E7DF%40gmail.com.


Re: Scripting a Find, then doing a second Find, searching in the first Find's results

2023-02-17 Thread Christopher Stone
On Feb 16, 2023, at 23:48, Bruce Van Allen  wrote:
> Chris, did you mean:
> $newSubject =~ s!\h!\%20!g;
> rather than
> $newSubject =~ s!\h!\$20!g;


Hey Bruce,

Yes indeed.

Thanks for catching my mistake.  :-)

--
Take Care,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/FECBEC61-718C-4F38-BF0A-E94992933CB5%40gmail.com.


Re: Scripting a Find, then doing a second Find, searching in the first Find's results

2023-02-16 Thread Christopher Stone
> On Feb 16, 2023, at 22:15, ChristianBoyce  wrote:
> ...
> In my new situation, I want to replace spaces with %20 but only in PART of 
> the selected text. I have text like this:
> [Joe J. Smith]mailto:j...@joesmith.com>> up!>
> 
> ...


Hey Christian,

You can't do this very easily with AppleScript, particularly because of the 
selected text requirement.

The only way I know of using AppleScript would be to loop the find using the 
selecting match option and to replace your spaces in the selected match.

You'd have to grab the first line and last line of the selection and test for 
those as you loop through. I've done this kind of thing now and then, and for a 
long document it's pretty slow.
a
You'd really expect to be able to find all instances and then loop through them 
directly, but unfortunately BBEdit doesn't support that.

Provided I didn't have to worry about "" spanning lines 
I'd do this with a Perl filter.

The selection goes to Perl as STDIN.  You can then loop through line by line 
testing for your pattern and when found replace the spaces in only it, and once 
complete the selection will be replaced with STDOUT.

Something like this should suffice, and compared to AppleScript it will be 
lightning quick.

#!/usr/bin/env perl -sw
# ----------
# Auth: Christopher Stone
# dCre: 2012/11/27 08:12
# dMod: 2023/02/16 23:18
# Task: Encode Spaces in Text Selection for a Given Pattern.
# Tags: @ccstone, @Shell, @Script, @Encode, @Spaces, @RegEx
# --
use v5.010;

while (<>) {
if ( m!(.+)()(.+)! ) {
my $prefixStr  = $1;
my $newSubject = $2;
my $suffixStr  = $3;

$newSubject =~ s!\h!\$20!g;
say $prefixStr . $newSubject . $suffixStr;
}
}

# --

--
Take Care,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/EB9E66F7-3F97-44CF-B830-0A9229CAF21D%40gmail.com.


Re: How to run N times a Text Factory?

2022-12-03 Thread Christopher Stone
> On Dec 02, 2022, at 07:42, Francisco Hirsch  wrote:
> 
> I have a Text Factory that I have to run N times on the same text.
> ...
> Is there a way that can run it N times or, even better, UNTIL there are no 
> changes?


Hey Francisco,

Text Factories have no method of looping, so you'll probably have to resort to 
AppleScript.

Can you post your Text Factory and some example text to test?

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/C9AE92BF-F2EB-4F91-BAB6-EDB0AE7DFA46%40gmail.com.


Re: Get the result of a replace in AppleScript

2022-10-14 Thread Christopher Stone


> On Sep 26, 2022, at 08:22, Lionel  wrote:
> 
> 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 ?


Hey Lionel,

I suppose you could look at it that way.  I know I cussed and carried on about 
having to manage quoting strings in AppleScript strings for a while. I even had 
a routine that did all the work on the clipboard with a regex osax way back in 
the day.

Then I bought Script Debugger  which has a built-in 
command for pasting-quoted, and I never looked back.

Keep in mind that the back-slash is a reserved character in AppleScript and as 
such must be escaped to be used as a literal.


tell application "BBEdit"
tell front text window's text
replace "\\x20{6}" using "••" options {search mode:grep, case 
sensitive:false, starting at top:true}
end tell
end tell


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/59D2F19E-F530-41E3-ADC5-01A8AD637655%40gmail.com.


Re: Get the result of a replace in AppleScript

2022-09-21 Thread Christopher Stone
> On Sep 20, 2022, at 10:46, Lionel  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 "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/7DC96F7E-5C88-443D-BBCF-4A9D36EE8DE6%40gmail.com.


Re: File links/URLs within BBEdit documents

2022-01-15 Thread Christopher Stone
> On Jan 12, 2022, at 11:50, jj  wrote:
> An easy way to get the URI of a document from the finder on macOS Monterey:


This is easy enough to automate...

-Chris


# Auth: Christopher Stone
# dCre: 2022/01/15 18:42
# dMod: 2022/01/15 18:42 
# Appl: Finder
# Task: Get File-URLs of Selected Items in the Front Finder Window.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Finder, @File-URLs, @Selected, @Items


tell application "Finder"
set finderSelectionList to selection as alias list
if length of finderSelectionList = 0 then error "No files were selected in 
the Finder!"
set theItem to item 1 of finderSelectionList

repeat with i in finderSelectionList
set contents of i to URL of i
end repeat

end tell

set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item 
delimiters, {""}}
set the clipboard to finderSelectionList as text
set AppleScript's text item delimiters to oldTIDS



-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/72F5A4AF-6549-4E7E-A5AF-8961D4803B28%40gmail.com.


Re: [ OFFLIST ] Need to increment a counter for chapter count

2022-01-09 Thread Christopher Stone
On Jan 07, 2022, at 15:10, David G Wagner  wrote:
> Here is the data that I am working with.


Hey David,

This is why it's so important to provide real-world data samples – both input 
and output – when asking for help to process text.

Here is a very robust method that lets you use a regular expression to split 
the text records.

The case of the split-string in insensitive and is also standardized in the 
file.

--
Best Regards,
Chris


#!/usr/bin/env perl
# 
-
# Auth: Christopher Stone
# dCre: 2022/01/09 13:36
# dMod: 2022/01/09 13:36
# Task: Number Lines Based On A Condition.
# Tags: @ccstone, @Shell, @Script, @Number, @Lines, @Condition, @bbedit-talk, 
@David_Wagner
# 
-

my $cntr= 1; 
my $recSep  = "#Start#";# Pseudo Input-Record-Separator
local $/= 0777; # Set Actual IRS to Slurp-Mode

$_ = <>;# Slurp up all the text
$_ =~ s!^$recSep!$recSep!gim;   # Standardize #Start# case
my @array = split /^$recSep\h*/im, $_;  # Split the text into an array

for my $element (@array) {  # Loop through the array and replace
$element =~ s!^1(?=\h)!$cntr++!em;  # the first instance of “^1” with $cntr
}

$, = $recSep;   # Set output-record-separator
print @array;

# 
-

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/12F87FED-0C62-4C0D-8D95-4839EBB66A34%40gmail.com.


Re: [ OFFLIST ] Need to increment a counter for chapter count

2022-01-07 Thread Christopher Stone
> On Jan 06, 2022, at 15:32, David G Wagner  wrote:
> I made mods to your code. I was not as clear as I should have been on 
> explanation desired results.


Hey David,

Using your input data sample my script exactly replicates your sample of 
desired output data format...

Your code does not work on the posted input data sample.

So what in fact does the actual input data look like?  Verbatim?

--
Best Regards,
Chris


Data Sample Provided by David Wagner:


#Start#
1 In the beginning, God created the heavens and
Xxccx
#EndOfGen#
#Start#
1 Thus the heavens and the earth were finished,
Xxxx
#EndOfGen#
#Start#
1 Now the serpent was more crafty than any other beast of the field that the 
LORD God had made.
Xxx
#EndOfGen#


Result when Perl Text Filter by CCS is run:


#Start#
1 In the beginning, God created the heavens and
Xxccx
#EndOfGen#
#Start#
2 Thus the heavens and the earth were finished,
Xxxx
#EndOfGen#
#Start#
3 Now the serpent was more crafty than any other beast of the field that the 
LORD God had made.
Xxx
#EndOfGen#


-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/1BA1D274-4E1A-4F90-8EBD-74F87E91405C%40gmail.com.


[ OFFLIST ] Re: Need to increment a counter for chapter count

2022-01-06 Thread Christopher Stone
Hey Chris,

This fails on my Mojave system with the stock `awk`.


#Start#Start#Start#
2 In the beginning, God created the heavens and
Xxccx
#Start#EndOfGen#Start#
#Start#Start#Start#
6 Thus the heavens and the earth were finished,
Xxxx
#Start#EndOfGen#Start#
#Start#Start#Start#
10 Now the serpent was more crafty than any other beast of the field that the 
LORD God had made.
Xxx
#Start#EndOfGen#Start#


It works if I use the current version of `gawk`.

It looks like David has an older version of macOS as well.

--
Take Care,
Chris


> On Jan 05, 2022, at 21:52, Christopher Waterman  wrote:
> 
> Sorry David,
> 
> I did make a mistake but the output you're getting still confuses me.
> All my chapter numbers were off by one, but that was it. 
> 
> Anyway here is the fixed script. ( I think 爛)
> 
> I provided an example of my input and output, also a screenshot.
> Be sure to copy the script exactly.
> 
> #!/usr/bin/env awk -f
> 
> BEGIN {
>   RS = "#Start#"
>   ORS = ""
>   FS = "\n"
>   OFS = "\n"
> }
> 
> { 
>   sub( /[0-9]+/, NR-1 , $2 )
> }
> 
> NR != 1 {
>   print "#Start#" $0
> }
> 
> Input:
> #Start#
> 1 In the beginning, God created the heavens and
> Xxccx
> #EndOfGen#
> #Start#
> 1 Thus the heavens and the earth were finished,
> Xxxx
> #EndOfGen#
> #Start#
> 1 Now the serpent was more crafty than any other beast of the field that the 
> LORD God had made.
> Xxx
> #EndOfGen#

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/18DA528B-9E6C-4B84-BAD4-1462489AB0ED%40gmail.com.


Re: Need to increment a counter for chapter count

2022-01-06 Thread Christopher Stone
On Jan 05, 2022, at 14:15, David G Wagner  wrote:
> I have data in one file and in one window. I could write a Perl script, but 
> was wanting to handle within BBEdit via filter or ?

Hey David,

A Perl script can be employed as a text filter, and that's probably as simple 
as anything.

~/Library/Application Support/BBEdit/Text Filters/


#!/usr/bin/env perl -sw
# 
-
# Auth: Christopher Stone
# dCre: 2022/01/06 06:35
# dMod: 2022/01/06 06:35
# Task: Number Lines Based On A Condition.
# Tags: @ccstone, @Shell, @Script, @Number, @Lines, @Condition, @bbedit-talk, 
@David_Wagner
# 
-

my $cntr = 0;

while (<>) {
if (/#Start#/) {
$cntr++;
}
if (/^\d+\h+/) {
s!^\d+!$cntr!;
}
print;
}

# 
-


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/AAE234A6-24A5-479F-B6C8-F43442453CF6%40gmail.com.


Re: Executing Multiple Saved Regular Expressions

2022-01-06 Thread Christopher Stone
On Jan 05, 2022, at 17:03, Peter Kaufman  wrote:
> I have stored over 2 dozen regular expressions stored under the "g" in 
> Find/Replace.
> I'd like to run 6 of them sequentially against a file.  Is there a way to do 
> this?

Hey Peter,

While Text Factories work well, I tend to use AppleScript for this sort of task.


tell application "BBEdit"
tell front text document's text
replace "Match-Pattern-1" using "Replace-Pattern" options {search 
mode:grep, case sensitive:false, starting at top:true}
replace "Match-Pattern-2" using "Replace-Pattern" options {search 
mode:grep, case sensitive:false, starting at top:true}
end tell
end tell


I find a AppleScripts easier to manage and work with than Text Factories.


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/3CC0FEB8-D28A-4531-B5C5-CFEFE9FFD5F7%40gmail.com.


Re: First Use - quick way to get a list of numbers for output

2021-12-30 Thread Christopher Stone
On Dec 30, 2021, at 13:49, Lorenz Groth  wrote:
> What I want to learn is how to produce a simple list of numbered word such as
> word01
> word02
> word03
> word04


Hey Lorenz,

The most direct method is probably to use a text filter like so:


#!/usr/bin/env bash

seq -w 200 | sed s'!^!Word!'


This filter is easily adjusted for length and will automatically pad the 
numbers appropriately.

It would be relatively easy to create a pop-up entry field for you to change 
the word(s) and sequence number at will.


BBEdit's text filters go here:

~/Library/Application Support/BBEdit/Text Filters/

And are accessed from:

BBEdit › Text › Apply Text Filter › ...


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/BF88F543-89DD-47E0-BCA6-2CCDED796BD9%40gmail.com.


Re: How to have \D ignore newline character?

2021-12-13 Thread Christopher Stone
> On Dec 12, 2021, at 23:38, Tim A  wrote:
> Deepening the challenge, the phone numbers are actually in the second of 
> three columns separated by tabs. If I can get the phone numbers stripped I 
> can then impose a uniform format on them.

Hey Tim,

Find:

[(]?(\d{3})\D*(\d{3})\D*(\d{4})

Replace:

\1-\2-\3


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/A6446566-AB8A-41E0-A9BF-C650D902835E%40gmail.com.


Re: Grep searching - how to ignore the first word of the sentence

2021-12-07 Thread Christopher Stone
> On Dec 07, 2021, at 17:50, Pavel  wrote:
> 
> Would anyone please know what must contain grep so that the first words of 
> the sentence do not appear in the search results? 

Hey Pavel,

Tom's idea is simpler, but you can do this:

Find:

(?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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/E23F92D1-442D-440F-8F32-6F6F9A4EB5BF%40gmail.com.


Re: Counting Text Strings In a Directory

2021-12-07 Thread Christopher Stone
> On Dec 07, 2021, at 20:44, Richard Fairbanks  wrote:
> I want BBEdit to return the number of times a text string appears in the 
> files in a directory. The following works to replace any such text:


Hey Richard,

The simple way is to do a straight file search:



If you want to script it then you need to do something like this:


# Auth: Christopher Stone
# dCre: 2021/12/07 22:17
# dMod: 2021/12/07 22:17 
# Appl: BBEdit
# Task: Count the Number of Files Containing a Search String – 
Recursive-File-Search
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @BBEdit, @Count, @Files, @Containing, 
@Search, @String, @Recursive, @Search

use AppleScript version "2.4" --» Yosemite or later
use framework "Foundation"
use scripting additions


set searchDir to "~/test_directory/Many_Files_6000/"

set searchDir to ((current application's NSString's 
stringWithString:searchDir)'s ¬
stringByExpandingTildeInPath) as text

tell application "BBEdit"
set foundRecord to find "three\\nfour" searching in searchDir options 
{search mode:grep, case sensitive:false, starting at top:true, returning 
results:true}

if found of foundRecord then
return length of found matches of foundRecord
end if

end tell




--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/650B3CC0-CC8A-49BE-BB65-999B9D3FC04A%40gmail.com.


Re: Custom sequencing

2021-12-06 Thread Christopher Stone
On Dec 06, 2021, at 09:31, Maciek Schejbal  wrote:
> I have 250 images to be shown in the slide show. After I copy the paths, 
> would anybody have a way to automate BBEdit to continue numbering the 
> following sequence?

Hey Maciek,

Please provide an accurate sample of the before state of your copied paths.

Once we see that your task should be pretty simple.


--
Best Regards,
Chris


-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/1BE12876-55CB-48B0-958E-E4FF72FAB5B7%40gmail.com.


Reposition the Selection Toward the Top of the Editing Window

2021-11-24 Thread Christopher Stone
On Nov 24, 2021, at 03:21, jj  wrote:
> It only has effect once your text overflows the window because it takes 
> advantage of the fact that, when jumping around, BBEdit repositions the 
> current line at ± 25% of the window height.

On Nov 24, 2021, at 03:26, jj  wrote:
> BTW, you should also set BBEdit Preferences > Editing > 'Extra vertical space 
> ("overscroll") in text view' to 'Full Window'.


Hey Folks,

In the thread “Re: Typewriter mode possible?” JJ presents an AppleScript that 
adds a linefeed and repositions the working line toward the top of the document.

I repurposed it to scroll the currently selected text (or bare cursor position) 
toward the top of the document (the top 25%) and to retain the selection if 
there is one or the cursor position if not.

I've been wanting this for ages.

Thanks JJ!

I have some Keyboard Maestro macros that kludge repositioning the working line 
to the top, middle, and bottom of the document, but they are clunky.

I fervently wish BBEdit could do this natively.  The Z editor (a superset of 
Vi) on Windows could do this way back in the early 90's.  At the time I thought 
that was pretty slick but a little bit of overkill – I've since edited hundreds 
of thousands of lines of code and learned otherwise.


--
Best Regards,
Chris

--------
# Auth: Christopher Stone { Building upon work by Jean Jourdain }
# dCre: 2021/11/24 20:41
# dMod: 2021/11/24 20:41 
# Appl: BBEdit
# Task: Attempt to reposition the working line to the top 25% of the working 
document.
# : Restores the cursor position or the selection if there is one.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Reposition, @Cursor, @Selection


try

tell application "BBEdit"
tell first window
set selectedText to its selection
tell its first document
select insertion point after its text
select selectedText
end tell
end tell
end tell

on error aMessage
display alert aMessage
end try



-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/E6A169E1-AD83-4B05-8CFE-D7B30F934633%40gmail.com.


Re: Search & Replace

2021-11-15 Thread Christopher Stone
> On Nov 15, 2021, at 15:18, R B COHEN  wrote:
> 
> 1 _GCID 94D0C28F-7346-4AC7-96D1-147294BADAF1

Hey R B,

Is this the start of the line?

Are these always _GCID numbers?

Is the hyphenated alphanumeric string always 36 characters?

Something like this:

Find:

(?-i)^.*[0-9A-Z]{8}-[0-9A-Z]{4}-[0-9A-Z]{4}-[0-9A-Z]{4}-[0-9A-Z]{12}.*\n?

Replace:

Nothing

> I then need to Find & Replace:
> 
> FIND:
> 
> 1 AFN  123.123.123  
> 
> REPLACE: 
> 
> 1 FACT 123.123.123  \n
> 2 TYPE Reference

Something like this:

Find:

(\d+)\h+AFN\h+\b(\d+\.\d+\.\d+)\b

Replace:

\1 FACT \2\n2 TYPE Reference\n

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/69FE4A06-4696-494E-9E94-157C083472D1%40gmail.com.


Re: The incredible shrinking selections.

2021-11-08 Thread Christopher Stone
> On Nov 08, 2021, at 00:14, Christopher Waterman  wrote:
> 
> If I select every occurrence of "whatsit" through which ever means.
> 
> ...
> 
> Then run this AppleScript.
> 
> AppleScript:
> tell window 1 of application "BBEdit"
>   set stuff to get selection
> end tell
> 
> It returns a list like this.


Hey Christopher,

I don't see how you're getting a list of selected items.

If I use find with show matches it doesn't work.

If I use LiveSearch it doesn't work.

So how exactly are you doing your selection?


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/FF7293C1-4C10-480A-B84F-1FAC72FE8A22%40gmail.com.


Re: Find and Replace multiple queries at once

2021-11-06 Thread Christopher Stone
> On Nov 05, 2021, at 22:43, Pu Koh  wrote:
> Thanks all. I shall look into the suggestions.
> Here's what I'm trying to do.
> I'm creating HTML 5 banners, and need to inject code for the click tags.
> The code looks like this:

Hey There,

Here's a super basic proof-of-concept.

--
Best Regards,
Chris


#!/usr/bin/env perl -sw

my $headData = q(


var clickTag = "X"; 
);

$headData = substr($headData, 2, -1);

my $canvasWrapper01 = q();
my $canvasWrapper02 = q();

while (<>) {
s!!$&\n$headData!i;
s!()!$canvasWrapper01$1$canvasWrapper02!i;
print;
}


-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/6BD8E9AF-4307-4705-B74B-E5F85F4EC88A%40gmail.com.


Re: Find and Replace multiple queries at once

2021-11-05 Thread Christopher Stone
> On Nov 05, 2021, at 06:00, Pu Koh  wrote:
> 
> Is there a function to run multiple find and replace patterns instead of 
> doing it one at a time?

Hey There,

Personally I would most often use a Text Filter and a little Perl, although it 
depends upon the context.  (See appended script.  See “Text Filter” in the 
manual if you don't know how to use them.)

NOTE: JJ's example text's tab separators got turned into spaces by the web. (At 
least in Apple Mail.)

Canon files can be a bit confusing, until you've used them a few times – but 
they can be very useful.

As Bruce suggested – a Text Factory 
is also a perfectly viable option.


--
Best Regards,
Chris


#!/usr/bin/env perl -sw

while (<>) {
s/\bnuts\b/NUTS!/g;
s/\bgoofy\b/GOOFY!/g;
print;
}


Sample Text:


nuts are pretty nutty nuts
nutso

goof
goofy is as goofy does.


-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/AD44E03D-1EEA-4A26-9C36-45385CA6E972%40gmail.com.


Re: Need easy way to make first letter of each line upper case

2021-10-28 Thread Christopher Stone
> On Oct 28, 2021, at 22:28, Nosadge  > wrote:
> 
> I'm defining lines as anything with a number infant of it.  I'm new to this 
> editor, and use it to edit transcripts, so my jargon will probably be 
> incorrect.


Hey Nosadge,

Did you mean a number in front of the line?

If so will the number always be at the beginning of the line, or might it be 
indented?

Will the number have punctuation?

Can you provide an example that includes all the possibilities?

Parsing text is pretty exacting.


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/472D7204-DFD9-4127-A3A2-CD6B3745D911%40gmail.com.


Re: Need easy way to make first letter of each line upper case

2021-10-28 Thread Christopher Stone
> On Oct 28, 2021, at 17:10, Nosadge  wrote:
> 
> Does anyone know a command/script/grep to make sure the first letter of every 
> line is capitalized?

Hey There,

How are you defining lines?

Line one.
Line two.
...

In that case Fletcher's regex works fine, although you might prefer to run it 
from a script.


#!/usr/bin/env perl -sw

while (<>) {
s!^.!\U$&!;
print;
}


See the section on Text Filters in the BBEdit Manual, if you don't know how to 
run one.

~/Library/Application Support/BBEdit/Text Filters/


Or did you mean sentences?


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/00F0D581-AC42-4541-AA67-FAAEF96F237A%40gmail.com.


Re: Easiest way to replace all matches

2021-10-21 Thread Christopher Stone
> On Oct 21, 2021, at 06:47, TJ Luoma  wrote:
> 
> Assume a 'regular' text file.
> 
> I'd like to be able to select a word, press a key, and have all instances of 
> that word be surrounded by {brackets}.

Hey Tj,

That's not overly difficult using a bit of AppleScript.

--
Take Care,
Chris


----
# Auth: Christopher Stone 
# dCre: 2021/10/21 10:33
# dMod: 2021/10/21 10:33 
# Appl: BBEdit
# Task: Enclose All Instances of the Selected Word with Curly Braces.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Enclose,@Instances, @Selected, @Word, 
@Curly, @Braces


tell application "BBEdit"
tell front text window's text
set theWord to the selection as text
set rePattern to "\\b" & theWord & "\\b"
replace rePattern using "\\{&\\}" options {search mode:grep, case 
sensitive:false, starting at top:true}
end tell
end tell



-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/0BC82778-B9FE-417A-A5B6-87CC90F9A397%40gmail.com.


Re: Make new HTML document from template in AppleScript: How?

2021-10-10 Thread Christopher Stone
> On Oct 07, 2021, at 23:11, Sonic Purity  wrote:
> Note: i write my stories in TE—that’s non-negotiable.

Hey Sonic,

Agh...

At least take a look at Jedit Ω (1,840 Yen ~ $16.00 USD).

http://www.artman21.com/en/jeditOmega/

It will do what TextEdit will do and a whole lot more.

You have to tweak some of the keyboard shortcuts, but like BBEdit Jedit has 
preferences for that.


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/1F100C9C-85D1-44AF-93DD-A30DD2DC5052%40gmail.com.


Re: Make new HTML document from template in AppleScript: How?

2021-10-04 Thread Christopher Stone
On Oct 04, 2021, at 18:30, Sonic Purity  wrote:
> I cannot figure out how to use AppleScript to create a new HTML document from 
> an existing template file, as i easily do manually via ^⌘N then select my 
> template then type in the title in the Title field and tap Create.

Hey Sonic,

That's easy enough if you already know how, but not so much if you don't.

Recording is relatively useless – except for discovering the syntax for some 
things that are really difficult to suss out.  A recorded script very often 
takes a lot of editing to convert from a very verbose and literal recording of 
actions to something that rationally makes sense to user, computer, and task.

Here's a sample template.  Note the underlined bold tags – these are 
placeholders you can tab to in the open document.





<#TITLE#>



<#HTML_BODY#>




You can use an AppleScript dialog to enter the title, but placeholders are 
easier.

This script uses the template-path defined with property templateFilePath.

It also contains code to demonstrate the use of an embedded template 
(commented-out).

--
Best Regards,
Chris


----
# Auth: Christopher Stone
# dCre: 2021/10/04 20:07
# dMod: 2021/10/04 20:07 
# Appl: BBEdit
# Task: Create a New HTML Document Using a Template File.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @BBEdit, @Create, @HTML, @Document, 
@Template

use AppleScript version "2.4" --» Yosemite or later
use framework "Foundation"
use scripting additions

property templateFilePath : "~/Documents/BBEdit 
Documents/Templates/HTML_Template_01.txt"
property defaultWindowBounds : {202, 45, 1238, 900} --» {X1, Y1, X2, Y2} 
Upper-Left, Lower-Right


set templateFilePath to ((current application's NSString's 
stringWithString:templateFilePath)'s stringByExpandingTildeInPath) as text
set templateText to read templateFilePath as «class utf8»

tell application "BBEdit"
# Create from a template FILE.
set newDoc to make new document with properties {text:templateText}

# Create using embedded template TEXT in handler getTemplateText().
# set newDoc to make new document with properties {text:my 
getTemplateText()}

tell newDoc
if its source language ≠ "HTML" then set its source language to "HTML"

tell its window
if its bounds ≠ defaultWindowBounds then
set its bounds to defaultWindowBounds
end if
end tell

end tell

end tell


# Template Text

on getTemplateText()
return text 2 thru -1 of "



<#TITLE#>



<#HTML_BODY#>


"
end getTemplateText



-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/623ADE4F-E213-4277-A714-3AA6FC838F44%40gmail.com.


Re: Split View possible?

2021-09-27 Thread Christopher Stone
On Sep 27, 2021, at 15:42, François Schiettecatte  
wrote:
> And you can also do Synchro Scrolling…


Hey François,

Thanks for mentioning that.  If I knew about it I'd forgotten.

Hey Jagrut,

François mentioned the arrange command, but if you need something more 
customized you can use AppleScript.


# Auth: Christopher Stone 
# dCre: 2021/09/27 18:24
# dMod: 2021/09/27 18:24 
# Appl: BBEdit
# Task: Set Bounds of Windows 1 and 2.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Window, @Bounds


tell application "BBEdit"

tell window 1
set its bounds to {0, 45, 720, 900}
end tell

tell window 2
set its bounds to {720, 45, 1440, 900}
end tell

end tell



This is just a simple example.  You can get quite creative in how you position 
your windows if you care to.

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/027F348D-4D4E-4277-9AAE-4A12AB1B0E40%40gmail.com.


Re: GEDCOM manipulation for one text tag (database transfer related)

2021-09-18 Thread Christopher Stone
> On Sep 18, 2021, at 15:19, Roger Moffat  wrote:
> 
> Thanks for this - I recommended Ryan to the geniuses on this list. I figured 
> it would be possible, but didn’t know where to begin to think about it.
> 
> Once the text of the NOTE tag has been moved to the  1 OCCU line, the entire 
> line
> 
> 2 NOTE 
> 
> can be deleted.

Hey Roger,

You bet.

Okay, try this:

Find:

^(\d+\h+OCCU\h+)(?:.+)(?s)(.+?)^\d+\h+NOTE\h+(?-s)(.+)\n

Replace:

\1\3\2

* This pattern is a bit different than the original.  RegEx101.com 
 didn't like the original, so I made a few changes.

You can get a better idea of how it works by looking on RegEx101 
:

https://regex101.com/r/w9ASKg/1 


BBEdit's Pattern Playground is a good place to experiment as well.

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/B1D87631-E4B9-46D2-A0E6-57A3174CFF8C%40gmail.com.


Re: GEDCOM manipulation for one text tag (database transfer related)

2021-09-18 Thread Christopher Stone
> On Sep 18, 2021, at 14:19, Ryan Noyes  wrote:
> Seeking workflow advice for wrangling a genealogical GEDCOM file in such a 
> way that content normally appearing within the red box in this screenshot, 
> instead populates where the green box is.

Hey Ryan,

You did a good job explaining the problem and providing a sample to work with.  
The only thing you left out was an actual example of the desired end result.

One has to guess what you want done with the NOTE field.

I'm assuming you want it left blank, but I don't like to assume...

Try this:

Find:

(?-i)^(\d+\h+OCCU\h+)(.+)((?s)(.+?)\n^\d+\h+NOTE\h)(?-s)(.+)

Replace:

\1\5\3


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/27B8C6DE-0020-4D34-AC36-63AF805B14E9%40gmail.com.


Re: Find followed by many lines of arbitrary HTML through next but exclude the second

2021-09-15 Thread Christopher Stone
> On Sep 15, 2021, at 00:51, ctfishman  wrote:
> 
> I tried doing this with just a regular expression but couldn't figure out how.

Hey There,

Yeah, you couldn't automate the whole process with regex alone.

> I was however able to do it quite easily with a text filter...
> 
> --
> 
> #!/usr/bin/perl
> 
> # Read each line into a scaler, then print it back
> 
> my $fullstring;
> 
> while (<>) {
> $fullstring .= $_;
> print;
> }

Looks good, although I'd shortcut the above with:


#!/usr/bin/env perl -0777 -nsw

print;


Now the entire string is in $_ and ready to process.


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/D625E3D2-F473-4FA1-8A2B-F404DC2FA76F%40gmail.com.


Re: Find followed by many lines of arbitrary HTML through next but exclude the second

2021-09-15 Thread Christopher Stone
> On Sep 14, 2021, at 16:57, Sonic Purity  wrote:
> Re-reading the Grep help file with BBEdit, i thought lookahead might help. I 
> tried:
> 
> ([\s\S]+?)(?)
> 

Hey There,

You miswrote your lookahead-assertion.

This:
> ([\s\S]+?)(?)
> 


Should look like this:


([\s\S]+?)(?=)


This is fine, except it will exclude your last chapter.


Try this instead:

(?s).+?(?=|\Z)


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/44B8E425-64DA-4A2F-B315-2E0E26E019BC%40gmail.com.


Re: Need way of counting number of occurrences of names

2021-09-09 Thread Christopher Stone
> On Sep 09, 2021, at 23:15, Bruce Van Allen  wrote:
> 
> Kerri's method was correct!


Indeed.

It's a great example of how useful a very simple regular expression can be.

:-)


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/E9263D10-A3A9-4D6F-BC0A-4C91B58C6CDC%40gmail.com.


Re: Need way of counting number of occurrences of names

2021-09-08 Thread Christopher Stone
> On Sep 08, 2021, at 10:05, Howard  wrote:
> I have multiple instances of this sample data (below) in which each 
> observation has at least three lines and is separated by a blank line. In 
> each observation, the first line contains a name, the second a time, and then 
> there is one or more lines of text:


Hey Howard,

This is a bit of a chore but not uber difficult using a Perl text filter.


--
Best Regards,
Chris


#!/usr/bin/env perl -0777 -nsw
# -----
# Auth: Christopher Stone 
# dCre: 2021/09/08 15:31
# dMod: 2021/09/08 15:31 
# Task: Concatenate Data Records and Count Same-Name-Keys.
# Tags: @ccstone, @Shell, @Script, @Perl, @Howard, @BBEdit-Talk
# -

# Trim vertical leading and trailing whitespace.
s!\A\s+|\s+\Z!!g;

# Trim trailing horizontal whitespace.
s!\h+$!!gm;

# Split the text records into an array.
my @array = split(/\n{2}/, $_);

# Concatenate the individual text records into a single line.
s!\n! -- !gm for @array;

# Set the Output Separator character.
$, = "\n";

print @array;
print "\n\nCounts:\n\n";

# Remove all text from records other than the name.
s!\h*--.+$!!gm for @array;

# Acquire counts for each record name (key) and print:
my %counts = ();

for (@array) {
   $counts{$_}++;
}

foreach my $keys (keys %counts) {
   print "$keys = $counts{$keys}\n";
}


-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/676F98B6-3F7D-4853-917F-2BC198B96220%40gmail.com.


Re: Save find/replace match to new file

2021-09-01 Thread Christopher Stone
> On Sep 01, 2021, at 09:07, Matthew Montgomery  wrote:
> 
> Your trusty script worked perfectly and has for sure saved me a nice chunk of 
> time. I really appreciate you sharing this.


Hey Matthew,

Super!

And you're welcome.


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/B9107334-88A8-48BF-9D6E-826096D4D474%40gmail.com.


Re: Save find/replace match to new file

2021-08-31 Thread Christopher Stone
On Aug 31, 2021, at 14:22, Matthew Montgomery  wrote:
> I’ve got a couple hundred lines in a tab delimited file that I need to 
> transform into one new YAML file per line. I’ve got the search and 
> replacement patterns all sorted out (thanks pattern playground!) but am 
> getting stumped on what I need to do to process the main file.

Hey Matthew,

While this job is not difficult, it's not simple either – particularly if 
you're not conversant with a scripting language.

You need to adjust the following variables in the script to meet your needs:

set regexFindPattern to "^(\\w.+)"
set regexReplacePattern to "• \\1"


When writing and testing AppleScript on macOS I advise folks to use Script 
Debugger <https://latenightsw.com/> – even if they don't write much AppleScript.

I've used it for 26 years plus and cannot begin to express how much it changed 
the AppleScript experience for me.

The commercial version is not inexpensive ($99.99), BUT it reverts to its FREE 
“Lite” version after a 30 day demo period – and the free version still beats 
the utter pants off of Apple's Script Editor.app.


You can run the script directly from Script Debugger (or the insipid Script 
Editor.app), or you can save it as a compiled script and run it from BBEdit's 
own Script menu.

~/Library/Application Support/BBEdit/Scripts/

New YAML files will be written to:

~/Downloads/New_YAML_Files/

--
Best Regards,
Chris


--------
# Auth: Christopher Stone 
# dCre: 2021/08/31 18:49
# dMod: 2021/08/31 18:49 
# Appl: BBEdit
# Task: Explode TSV Document into One YAML File Per Line.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @BBEdit, @Explode, @TSV, @Document, 
@YAML

use AppleScript version "2.4" --» Yosemite or later
use framework "Foundation"
use scripting additions

--» USER SETTINGS

set regexFindPattern to "^(\\w.+)"
set regexReplacePattern to "• \\1"
set new_YAML_Files_Destination to "~/Downloads/New_YAML_Files"


set fileNameCounter to 0
set new_YAML_Files_Destination to ((current application's NSString's 
stringWithString:new_YAML_Files_Destination)'s stringByExpandingTildeInPath) as 
text
its createDirectoryAtPathWithIntermediates:new_YAML_Files_Destination
set itemFound to true

tell application "BBEdit"

set frontDoc to a reference to the front text document
select insertion point before character 1 of frontDoc

repeat while itemFound

set findRecord to find regexFindPattern searching in frontDoc options 
{search mode:grep, case sensitive:false, wrap around:false}

if found of findRecord ≠ true then

return

else

select found object of findRecord
set newText to replace regexFindPattern using regexReplacePattern 
searchingString (get found text of findRecord) options {search mode:grep, case 
sensitive:false, starting at top:true}
set fileNameCounter to fileNameCounter + 1
set newFileName to "File_Name " & fileNameCounter & ".yaml"
set targetFilePath to new_YAML_Files_Destination & "/" & newFileName
write_UTF8(newText, targetFilePath) of me

end if

end repeat

end tell


--» HANDLERS

on createDirectoryAtPathWithIntermediates:thePath
set {theResult, theError} to current application's NSFileManager's 
defaultManager()'s createDirectoryAtPath:thePath ¬
withIntermediateDirectories:true attributes:(missing value) 
|error|:(reference)
if not (theResult as boolean) then
set errorMsg to theError's localizedDescription() as text
error errorMsg
end if
end createDirectoryAtPathWithIntermediates:

on write_UTF8(_text, targetFilePath)
try
if targetFilePath starts with "~/" then
set targetFilePath to POSIX path of (path to home folder as text) & 
text 3 thru -1 of targetFilePath
end if
set fRef to open for access targetFilePath with write permission
set eof of fRef to 0
write _text to fRef as «class utf8»
close access fRef

if targetFilePath contains ":" then
return alias targetFilePath
else if targetFilePath starts with "/" then
return alias POSIX file targetFilePath
end if

on error e number n
tr

Re: script/text filter advice

2021-08-30 Thread Christopher Stone
On Aug 29, 2021, at 21:12, Tim Gray  wrote:
> Is AppleScript the best/most powerful way to script text manipulation based 
> on where the cursor currently is?

Hey Tim,

Basically.  Although as JJ mentions environment variables offer a good deal of 
information to shell scripts, it's more complicated to use that information in 
the shell than with AppleScript.

Here's your basic AppleScript for the task:


# Auth: Christopher Stone 
# dCre: 2021/08/30 04:02
# dMod: 2021/08/30 04:02 
# Appl: BBEdit
# Task: Working with the selection in the front text window.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Selection, @Text, @Window


tell application "BBEdit"
tell front text window

--» Acquire relevant information about the selection.
tell selection
set selectionLength to its length
set start_Line to its startLine
set end_Line to its endLine
end tell

--» Process the selection.
if selectionLength = 0 or start_Line = end_Line then
# Process line start_Line.
else
# Process lines start_Line through end_Line.
end if

end tell
end tell



Let us know if you need any more help.


--
Best Regards,
Chris


-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/6F5238B6-5EF6-4674-9630-86B063A33BD5%40gmail.com.


Re: Bespoke preferences

2021-08-29 Thread Christopher Stone
> On Aug 29, 2021, at 05:48, 'Michael Hall' via BBEdit Talk 
>  wrote:I think I'm asking for a particular set of 
> preferences based on the type of file I want to edit. Currently I'm opening a 
> file and making the preference changes before I start to edit. Surely BBEdit 
> has a way of doing this that I have missed.

Hey Michael,

You can customize BBEdit a great deal with AppleScript.

Run this from Apple's Script Editor.app to see how it works.

----
# Auth: Christopher Stone 
# dCre: 2021/08/29 16:32
# dMod: 2021/08/29 16:32 
# Appl: BBEdit
# Task: Set Up Markdown Document Work Environment
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @BBEdit, @SetUp, @Markdown, @Work, 
@Environment


tell application "BBEdit"
activate
set newDoc to make new text document
tell newDoc
set its source language to "Markdown"
tell its window
set bounds to {0, 45, 1440, 900}
if show line numbers ≠ false then
set show line numbers to false
end if
end tell
end tell
end tell



Save it as a compiled script, and place it in BBEdit's Script menu.

~/Library/Application Support/BBEdit/Scripts/

Give it a keyboard shortcut in BBEdit's Menus & Shortcuts preferences.

Go to town.

There are more AppleScript properties available.

I recommend using Script Debugger <https://latenightsw.com/> instead of Apple's 
Script Editor.app, because SD eats SE's lunch.  

(Even if you don't buy SD and only use the freeware “Lite” version it becomes 
after a 30 day demo period you will still appreciate the vast difference in 
capability.)

You can create hotkey driven scripts for each document type you want to work 
with.

Or – you can create a pop-up dialog with a pick-list of document types.

The world is not your oyster, but there is quite a lot of flexibility available 
to you.

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/45271847-7A6B-48F6-96C4-98FF11FE1E05%40gmail.com.


Re: How to format this text so it expands and fits page width?

2021-08-24 Thread Christopher Stone
> On Aug 24, 2021, at 10:39, David J  wrote:
> 
> Oh, one last thing. Is there a save all command available after doing this?

Hey David,

AppleScript can do many things...


# Auth: Christopher Stone
# dCre: 2021/08/22 16:43
# dMod: 2021/08/24 20:30
# Appl: BBEdit
# Task: Remove Line Breaks from Text Documents of Project Window 1.
# : Then Hard Wrap to the Given Length.
# : Then save each document.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Remove, @Line, @Breaks, @Project, 
@Window

property hardWrapWidth : 70


tell application "BBEdit"

set docList to text documents of project window 1

repeat with theDoc in docList
tell theDoc
tell its text
remove line breaks
hard wrap width hardWrapWidth
end tell
save
end tell
end repeat

end tell




--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/D04E9094-968A-45F7-B2FE-15148A630DB8%40gmail.com.


Re: How to format this text so it expands and fits page width?

2021-08-23 Thread Christopher Stone
> On Aug 22, 2021, at 22:58, David J  wrote:

> Since the end goal was to get the text so I could hard wrap it by removing 
> all line breaks first. Is there any easy way to add an additional hard wrap 
> on all open documents to the above script?

Hey David,

Sure.

----
# Auth: Christopher Stone
# dCre: 2021/08/22 16:43
# dMod: 2021/08/23 12:27
# Appl: BBEdit
# Task: Remove Line Breaks from Text Documents of Project Window 1.
# : Then Hard Wrap to the Given Length.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Remove, @Line, @Breaks, @Project, 
@Window

property hardWrapWidth : 70


tell application "BBEdit"

set docList to text documents of project window 1

repeat with theDoc in docList
tell theDoc's text
remove line breaks
hard wrap width hardWrapWidth
end tell
end repeat

end tell




--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/E8AE427B-9FB4-4435-AC26-9545098D985A%40gmail.com.


Re: How to format this text so it expands and fits page width?

2021-08-22 Thread Christopher Stone
> On Aug 21, 2021, at 20:07, David J  wrote:
> 
> If I have multiple files open, can I remove line breaks from them all at 
> once? I've selected all open documents that are in the side tabs, but the 
> remove line breaks option is greyed out. 

Hey David,

You can do something like this:

----
# Auth: Christopher Stone
# dCre: 2021/08/22 16:43
# dMod: 2021/08/22 16:43 
# Appl: BBEdit
# Task: Remove Line Breaks from Text Documents of Project Window 1.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Remove, @Line, @Breaks, @Project, 
@Window


tell application "BBEdit"

set docList to text documents of project window 1

repeat with theDoc in docList
tell theDoc's text to remove line breaks
end repeat

end tell



Note that this works only on documents open in the front project window.

The script can be altered to operate on any open document.

--
Best Regards,
Chris


-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/66EFA0DB-CCBC-4888-8939-4EB6C076247A%40gmail.com.


Re: How to move #tags up to line above and sort doc by tags?

2021-08-19 Thread Christopher Stone
On Aug 19, 2021, at 12:20, David J  wrote:
> I have a long text that I tagged, I'd like to move those tags up to the end 
> of the last line they are under:

Hey David,

I'm thinking something like this:

Find:

\s+((?:#\w+\h*)+)

Replace:

“ \1”

** Without the quotes.


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/20F91954-2C47-46A0-806B-4E65F9CC%40gmail.com.


Re: Copying grep match to clipboard

2021-08-15 Thread Christopher Stone
> On Aug 13, 2021, at 21:30, e2o  wrote:
> 
> Howdy! Is there an easy way to copy a chunk of text matched with a regular 
> expression to the clipboard only? No search/replace.
> 
> I have an expression that selects everything at the beginning of a document 
> up to but not including the first blank line. I need to copy this text and 
> copy it to the bottom of the document. I can't use Process Lines Including 
> because it uses \A to match beginning of document, which doesn't fly there.
> 
> So my expression is:
> \A.*\r(^\S.*\r)+
> 

Hey Eric,

Your pattern does not fully match your verbal description.  Whenever asking for 
text processing help please always include at least one good real-world before 
and after example.

Doing so will always save yourself and anyone who helps you both time and 
aggravation.

>From what I understand your task is really just a simple find/replace.

AppleScriptified:

-------
# Auth: Christopher Stone
# dCre: 2021/08/15 09:01
# dMod: 2021/08/15 09:01 
# Appl: BBEdit
# Task: Copy text from (the beginnging of a document to the first blank line) 
to the end of document.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @RegEx
# Note: Posted to BBEdit-Talk for .
---

tell application "BBEdit"
tell front text document's text
replace "(?ms)(\\A.*?)(?=^$)(.+)" using "\\1\\2\\n-\\n\\1" options 
{search mode:grep, case sensitive:false, starting at top:true}
end tell
end tell

---

Using a Text Factory would be the simplest method, but as you can see the 
AppleScripted version isn't particularly difficult.

I've added a separator for a visual cue, which you can change as you like.

Now then – let's tackle the task as you describe it via AppleScript but without 
using the clipboard, since copy and paste is completely unnecessary.

Knowing how to do this may come in handy some time.

-------
# Auth: Christopher Stone
# dCre: 2021/08/15 09:01
# dMod: 2021/08/15 09:19
# Appl: BBEdit
# Task: Copy text from (the beginnging of a document to the first blank line) 
to the end of document.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @RegEx
# Note: Posted to BBEdit-Talk for .
---
property LF : linefeed
---

tell application "BBEdit"

tell front text document's text

set findRecord to find "(?ms)(\\A.*?)(?=^$)" options ¬
{search mode:grep, case sensitive:false, starting at top:true}

if found of findRecord is true then
set after it to LF & LF & findRecord's found text
end if

end tell

end tell

---

Doing it this way isn't particularly difficult either, even if it's a little 
less straightforward.

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/96640180-0C63-4CAC-BF0C-FE95C0BF93E6%40gmail.com.


Re: Set selection point to next line in AppleScript

2021-08-05 Thread Christopher Stone
> On Aug 05, 2021, at 05:15, Rainer Krug  wrote:
> 
> I have the following AppleScript to execute het selected text in R and return 
> the focus to BBEdit:
> ...
> Now I would like to set the cursor in BBEDit to the next line after the 
> selected text ore line it is in.

Hey Rainer,

You can do something like this.

--
Best Regards,
Chris


tell application "BBEdit"

set startLineNum to startLine of selection
set selectedText to selection's contents

if selectedText is "" then
try
set selectedText to contents of line startLineNum of front document
on error
display dialog "The active window must be an editor window, with a 
file opened. You want to run something in R? Well, tell me what!" with icon 
note buttons {"Got it!"} default button 1
error number -128
end try
end if

end tell

tell application "R"
cmd the_selection
end tell

tell application "BBEdit"
activate
tell front document
try
select insertion point before line (startLineNum + 1)
on error
select insertion point after line startLineNum
end try
end tell
end tell


-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/2396E259-9608-4CEA-B626-EC8E0FAB4E88%40gmail.com.


Re: BBEdit 14.0.1 – Scroll Text Up Past Bottom of Window

2021-08-04 Thread Christopher Stone
> On Aug 02, 2021, at 04:39, Tom Robinson  wrote:
> 
> I think you missed the annotated screenshot Rich attached :]


Hey Tom,

Eh?

Hmm...  Sure enough.  I see it in the group online.

I was sure the image was missing from my copy of the message in Mail (Mojave), 
but I just checked – and it's there.

Thanks for pointing that out.

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/619B3530-A9CF-4921-A710-7EB66B9B935B%40gmail.com.


Re: BBEdit 14.0.1 – Scroll Text Up Past Bottom of Window

2021-08-02 Thread Christopher Stone
> On Aug 02, 2021, at 03:11, Jan Erik Moström  wrote:
> 
> On 2 Aug 2021, at 10:04, Christopher Stone wrote:
> 
>> It's  _not_  listed in the expert settings for BBEdit 14.x.
> 
> Open preferences, select "Editing", about 2/3 down "Extra vertical space"


Hey Jan,

Super!

Many thanks.

That's the first place I looked, but I didn't recognize the name.

--
Take Care,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/93DB29DB-0362-4009-A73D-2F1A12406C33%40gmail.com.


Re: BBEdit 14.0.1 – Scroll Text Up Past Bottom of Window

2021-08-02 Thread Christopher Stone
Hey Rich,

Well, where?

It's not listed in the expert settings for BBEdit 14.x.

https://www.barebones.com/support/bbedit/ExpertPreferences.html

--
Best Regards,
Chris


> On Aug 01, 2021, at 20:25, Rich Siegel  wrote:
> 
> On 1 Aug 2021, at 18:47, Christopher Stone wrote:
> 
>> Hey Folks,
>> 
>> BBEdit 12.x allowed the user to scroll text up past the bottom of the 
>> window, so you could conveniently position the cursor in your comfort zone 
>> without having to add blank lines to the end of your text.
>> 
>> I'm looking in the prefs and expert prefs and can't find the setting.
>> 
>> Could someone point me in the right direction?
> 
> Same place; same setting.
> 
> R.

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/6DB25A94-919F-4FCE-BD49-732FFC87BB8D%40gmail.com.


Re: BBEdit 14.0.1 – Scroll Text Up Past Bottom of Window

2021-08-01 Thread Christopher Stone
> On Aug 01, 2021, at 18:42, Christopher Waterman  wrote:
> 
> I think it’s.
> 
> defaults write com.barebones.bbedit ExtraSpaceInTextViews -bool YES


Hey Christopher,

That didn't work for me, but it helped me do some sleuthing.

There is NO “ExtraSpaceInTextViews” pref in the currently listed expert prefs 
for BBEdit 14.

However – this string worked for me (thankfully):

defaults write com.barebones.bbedit ExtraSpaceInTextViews -string "ESfp"


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/89B25C25-5C44-49D5-B20C-1218D013E504%40gmail.com.


BBEdit 14.0.1 – Scroll Text Up Past Bottom of Window

2021-08-01 Thread Christopher Stone
Hey Folks,

BBEdit 12.x allowed the user to scroll text up past the bottom of the window, 
so you could conveniently position the cursor in your comfort zone without 
having to add blank lines to the end of your text.

I'm looking in the prefs and expert prefs and can't find the setting.

Could someone point me in the right direction?

TIA.

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/58A62235-5BB2-4095-BF7C-2A03D71C5505%40gmail.com.


Re: Need to extract all digits from string

2021-07-29 Thread Christopher Stone
On Jul 29, 2021, at 00:19, Tim A  wrote:
> How to not include the brackets as Howard asked? I figure it involves 
> non-capture but it eludes me.

Eh?  Hmm. I must have been tired.

Find:

\[(\d+)\]|(\d)

Replace:

\1\2\n


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/480456D3-285F-4986-BC68-FF97E086362E%40gmail.com.


Re: Need to extract all digits from string

2021-07-27 Thread Christopher Stone
Hey Howard,

What exactly do you mean by “regmatches”?

Find:

(\d|\[\d+\])

Replace:

\1\n

--
Best Regards,
Chris


> On Jul 27, 2021, at 14:41, Howard  > wrote:
> 
> I have a string of numbers like this:
> 
> "12[11]4567[10]0"
> 
> The string may be longer or shorter than the one shown above. The numbers 
> within the brackets always contain two digits.
> 
> I need to extract the numbers so they appear like below, each number a 
> separate element. The format does not have to be vertical. I am just 
> presenting it that way for readability. 
> 
> 1
> 2
> 11
> 4
> 5
> 6
> 7
> 10
> 0
> 
> How can I do this using GREP and, if viable, 'regmatches'? 

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/2E29EDF1-2AC0-469F-82B9-060D634B1CF5%40gmail.com.


Re: Script help - Convert untitled text to notes

2021-07-23 Thread Christopher Stone
> On Jul 23, 2021, at 10:03, Jim Straus  wrote:
> 
> I've created a script to convert all my untitled text documents to notes 
> (kind of surprised something like this wasn't provided with the release of 
> BBEdit 14).  It generally works, but for some notes the body is empty.  If I 
> put in a dialog with the text, it works, but that means I have to respond to 
> each dialog.
> 
> Any thoughts on how to fix this?

Hey Jim,

It would be nice if Rich added a make new note command to the AppleScript 
dictionary, but this should work for now.

I recommend commenting-out close theDoc until you're confident the script works 
as intended.

--
Best Regards,
Chris


--------
# Auth: Christopher Stone
# dCre: 2021/07/23 10:57
# dMod: 2021/07/23 10:57 
# Appl: BBEdit, System Events
# Task: Convert Unsaved Documents into Notes.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @System_Events, @Convert, @Unsaved, 
@Documents, @Notes
# Test: Only on macOS 10.14.6 Mojave
# Vers: 1.00


tell application "BBEdit"

set docList to text documents whose name starts with "untitled" and on disk 
is false

repeat with theDoc in docList
if (length of theDoc's text > 0) then
select theDoc
select theDoc's text
saveSelectedTextAsNote() of me
close theDoc
end if
end repeat

end tell


--» HANDLERS

on saveSelectedTextAsNote()
tell application "System Events"
tell application process "BBEdit"
tell menu bar 1
tell menu bar item "File"
tell menu 1
tell menu item "Save as Note"
perform action "AXPress"
end tell
end tell
end tell
end tell
end tell
end tell
end saveSelectedTextAsNote


-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/B908AB4C-47D5-48D6-9033-3ED67CED4584%40gmail.com.


BBEdit 14 Debuts

2021-07-19 Thread Christopher Stone
> On Jul 19, 2021, at 13:39, Rich Siegel  wrote:
> We are pleased to announce the release and immediate availability of BBEdit 
> 14.0. This major upgrade adds over a hundred new features, improvements to 
> existing features, and minor refinements.


Color me impressed...

Thanks Rich!

--
Take Care,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/117A2156-9493-4DA5-B7DB-6C5FA1BE53FA%40gmail.com.


Re: TextFactory and then AppleScript works; AppleScript in TextFactory doesn't

2021-07-07 Thread Christopher Stone
On Jul 05, 2021, at 16:13, Francisco Hirsch mailto:listas.hir...@gmail.com>> wrote:
> I have a TextFactory and an AppleScript.
> I do the following:
> Open pdf in Acrobat
> Select all, copy, paste in a new BBEdit Window, process with the TextFactory, 
> run the AppleScript clicking in BBEdit Scripts, and everything works.
> But if I include the AppleScript as the last line in the TextFactory:
> It saves the original text copied from the pdf with it’s first line as it’s 
> name.
> In other words, it’s as if the script (up to AppleScript line) did not work 
> or the text was substituted in the AppleScript.

Hey Francisco,

This issue can be confusing, but as Rich says Text Factory are not designed to 
run AppleScripts per se – they're designed to run AppleScripts (and other 
tools) that transform text.

This means the last line of the handler must always return text.  Like so:

---
property LF : linefeed

on ApplyTextTransform(bbeditData)

return "Returned Data Start" & LF & bbeditData & LF & "Returned Data End"

end ApplyTextTransform
---

And that means the AppleScript cannot process the front document, beyond its 
purview.

To do what you want you'll need to run your AppleScript from the BBEdit script 
menu (or FastScripts <https://www.red-sweater.com/fastscripts/>, Keyboard 
Maestro <https://www.keyboardmaestro.com/main/>, or another AppleScript runner 
app.)

Something like this:

-------
# Auth: Christopher Stone mailto:scriptmeis...@thestoneforge.com>>
# dCre: 2021/07/06 00:26
# dMod: 2021/07/06 00:51
# Appl: BBEdit, System Events
# Task: Run a BBEdit Text Factory on the Front Document from an AppleScript.
# : Save front document to a file name based on its own line 1's text.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @System_Events, @Text_Factory, @Save
---
# NOTE – ALWAYS use relative paths whenever possible.
# Hard-coded paths are a recipe for headaches in the future.
---

set myHomePath to path to downloads folder as text

# The way I generally use relative-paths when working with aliases.
# set textFactory to alias ((path to application support from user domain as 
text) & "BBEdit:Text Filters:Text Factories:TEST ⇢ Change Case to 
UpperCase.textfactory")

# How to use a relative POSIX Path with System Events.
# In this use-case the file must already exist.
set textFactory to "~/Library/Application Support/BBEdit/Text Filters/Text 
Factories/TEST ⇢ Change Case to UpperCase.textfactory"
tell application "System Events" to set textFactory to POSIX path of disk item 
textFactory

tell application "BBEdit"

set theDoc to front text document

apply text factory textFactory to theDoc

set textOfLine1 to contents of line 1 of theDoc

if textOfLine1 ≠ "" then

set newFileName to textOfLine1 & ".txt"
set newFilePath to myHomePath & newFileName
save theDoc to file newFilePath
close front window

make new text document

else
error "Line 1 was blank – file was NOT saved!"
end if

end tell

---

Personally I would not copy and paste the PDF data.

I'd either use the command line utility `pdftotext` from Xpdf Tools or 
AppleScriptObjC to perform the extraction.

I like `pdftotext`, because it has a `-layout` switch that does a very 
respectable job of preserving the original PDF's format – unlike copy/paste 
from Preview.app and extract text with AppleScriptObjC.  This can be 
monumentally useful when parsing the text.

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/0CB0A87A-4BAE-4B3E-927C-327FDB783E1E%40gmail.com.


Re: Searching an html tag with Applescript and BBEdit

2021-06-29 Thread Christopher Stone
On 06/29/2021, at 00:37, Murat mailto:myi...@gmail.com>> 
wrote:
> set result to (find "" searching in ¬
> (alias "full HFS path to my file") ¬
> options {starting at top:true} with selecting match)
> 
> if (found of result) then .
> 
> Script debugger tells me, for the last line
> Variable result is undefined.
> 
> If I execute with option returning results, the variable is defined but its 
> structure does not correspond with what the script given in the manual for 
> the replacement part expects as structure...


Hey Murat,

Do not make a habit of using the result variable in AppleScript.  It's too 
mutable and makes debugging more difficult.

When you search a file on disk BBEdit's file search browser is activated, and 
the found result of the AppleScript is omitted.

To get a found result you can do something like this.


set fileAlias to alias "MyHD:Users:UserName:Downloads:Test.ccs.txt"

tell application "BBEdit"
set docRef to open fileAlias
set foundRec to (find "Now.+" searching in docRef options {starting at 
top:true, search mode:grep}) # with selecting match
end tell


To use this script you have to change the path to the file.

Let's make that just a bit more turnkey.


set fileAlias to alias ((path to downloads folder as text) & "Test.ccs.txt")

tell application "BBEdit"
set docRef to open fileAlias
set foundRec to (find "Now.+" searching in docRef options {starting at 
top:true, search mode:grep}) # with selecting match
end tell


Now if we have the file with the same name in the same relative location there 
is no need to change the path.

You could also write that using a Unix style relative path.  BBEdit 


set filePath to "~/Downloads/Test.ccs.txt"
tell application "System Events" to set fullFilePath to POSIX path of disk item 
filePath

tell application "BBEdit"
set docRef to open fullFilePath
set foundRec to (find "Now.+" searching in docRef options {starting at 
top:true, search mode:grep}) # with selecting match
end tell



--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/A5AFE8F3-D845-43B6-B2F8-C144DB94DC1C%40gmail.com.


Re: Scripts

2021-06-28 Thread Christopher Stone
On 06/28/2021, at 04:35, Paul G mailto:p...@profile-music.com>> wrote:
> Would anyone be up to writing a couple of basic scripts for me to use in 
> BBEdit?
> If so let me know price.
> 
> I just need a script to alphabetically sort lines within certain parameters 
> inside a text doc and another to replace certain text within a text doc.


Hey Paul,

Replacing text with AppleScript is easy enough once you know how:

-------
# Auth: Christopher Stone
# dCre: 2021/06/28 21:28
# dMod: 2021/06/28 21:37
# Appl: BBEdit
# Task: Replace Either RegEx or Literal Text in the Designated BBEdit Window.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Replace, @RegEx, @Literal
---

# Use "Front_Text_Window" to Target the Front Window.
# Otherwise use the Window Name as the targetWindow.

# REMEMBER - The backslash for RegEx metacharacters "\" must be escaped in 
AppleScript "\\".

# Verbose:
set matchStr to "Nyet\\s"
set replaceStr to "Da"
set targetWindow to "Front_Text_Window"
set grepFlag to {|regEx|:true}
bbeditReplaceMatchInTargetWindow(matchStr, replaceStr, targetWindow, grepFlag)

# Less Verbose:
# bbeditReplaceMatchInTargetWindow("Nyet\\s", "Da", "Front_Text_Window", 
{|regEx|:true})

---
--» HANDLERS
---
on bbeditReplaceMatchInTargetWindow(matchStr, replaceStr, targetWindow, 
grepFlag)

tell application "BBEdit"
if targetWindow = "Front_Text_Window" then
set targetWindowRef to a reference to the front text window
else
set targetWindowRef to a reference to text window targetWindow
end if

if grepFlag's |regEx| = true then
set searchModeType to grep
else
set searchModeType to literal
end if

# Case-Sensitive is OFF by Default – Switch on using (?-i)
tell targetWindowRef's text
replace matchStr using replaceStr options {search 
mode:searchModeType, starting at top:true}
end tell

end tell

end bbeditReplaceMatchInTargetWindow
---

Sorting lines “within certain parameters” requires more explanation.  Please 
provide real world examples.

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/5966CF7B-80BF-4D13-871F-96981C854A9D%40gmail.com.


Re: AppleScript to make window wide enough to not scroll?

2021-06-26 Thread Christopher Stone
On 06/26/2021, at 20:32, TJ Luoma mailto:luo...@gmail.com>> 
wrote:
> I’m not sure if that’s something that can easily be changed (just to make the 
> scrollbar disappear) but if not that’s really a minor nit.


Tweak one of these properties until its wide enough:

property gutterWidth : 64
property gutterPad : 18
property scrollbarWidth : 16


-Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/BD20AF15-5EB8-4E15-83FC-DC29ED5B655B%40gmail.com.


Re: Looking for Preference: Prevent Scrollbar possible ?

2021-06-26 Thread Christopher Stone
On 06/26/2021, at 04:50, Wastle Smith mailto:wastlesm...@gmail.com>> wrote:
> With that I want to prevent horizontal scrolling (e.g. due to an over-size. 
> long line ). Instead I want that the window is resized.  Great enough to 
> prevent that type of scrolling (which often then hides the beginning of the 
> lines).
> 
> Is there a preference available to setup BBEdit to have this behavior?


Hey Wastle,

No, there is no such setting – but some enterprising fellow wrote an 
AppleScript to handle that:

https://groups.google.com/g/bbedit/c/IxNvYyiYCAA/m/Yzf2AhBtAQAJ 


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/E0C98062-4E33-4B56-A0D9-87AAA5D70548%40gmail.com.


Re: AppleScript to make window wide enough to not scroll?

2021-06-26 Thread Christopher Stone
Hey Tj,

Here is the newest version of the script.

CHANGES:

- macOS versions Sierra through Big Sur are supported automatically.
- The font name and font size are managed automatically.
- It sets the document magnification level to 1 if necessary.

--
Take Care,
Chris

---
# Auth: Christopher Stone { Kudos to Shane Stanley for generous help with 
ASObjC }
# dCre: 2018/09/16 22:24
# dMod: 2021/06/26 19:08
# Appl: BBEdit
# Task: Resize width of front BBEdit window according to longest line and 
center.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @BBEdit, @Resize, @Width, @Front, 
@Window, @Longest, @Line, @Center
# Vers: 2.00
---
use AppleScript version "2.5" -- macOS 10.13 or later
use framework "Foundation"
use framework "AppKit"
use scripting additions
---
property minimumLineWidth : 500
property gutterWidth : 64
property gutterPad : 18
property scrollbarWidth : 16
---

if systemGreaterthanSierra() = true then
set screenWithMenu to current application's NSScreen's screens()'s 
objectAtIndex:0
set screenWithMenuFrameSize to screenWithMenu's frame()
set screenWidth to (item 1 of item 2 of screenWithMenuFrameSize) as 
integer
else
set screenWithMenu to current application's NSScreen's screens()'s 
objectAtIndex:0
set screenWithMenuFrameSize to (screenWithMenu's frame()'s |size|()) as 
list
set screenWidth to (item 1 of screenWithMenuFrameSize) as integer
end if

set longestLineLength to 0
set maxLineContent to missing value

set lineCounter to 0

set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item 
delimiters, linefeed}

tell application "BBEdit"
if exists of front text window then
tell front text window
display magnification
if display magnification ≠ 1 then set display 
magnification to 1
set displayFontName to display font
set displayFontSize to display font size
set lineContentList to text items of (get its text)
end tell
end if
end tell

set AppleScript's text item delimiters to oldTIDS

repeat with i in lineContentList
set lineCounter to lineCounter + 1
set lineLength to length of i
if lineLength > longestLineLength then
set longestLineLength to lineLength
set longestLineNumber to lineCounter
end if
end repeat

tell application "BBEdit"
tell front document
set widestLineContent to contents of line longestLineNumber's 
text
end tell
end tell

set theFont to current application's NSFont's fontWithName:displayFontName 
|size|:displayFontSize
set theAtts to current application's NSMutableDictionary's ¬
dictionaryWithObject:theFont forKey:(current application's 
NSFontAttributeName)

set atrString to (current application's NSAttributedString's alloc()'s 
initWithString:widestLineContent attributes:theAtts)
set theSize to atrString's |size|()
set lineWidth to round (width of theSize)

if lineWidth < minimumLineWidth then
error "Text content is too narrow to resize the window!"
end if

set newWindowWidth to lineWidth + gutterWidth + gutterPad + scrollbarWidth

--» Set the Window Width.
tell application "BBEdit"
tell front window

if newWindowWidth > screenWidth then

set {null, y1, null, y2} to (get its bounds)
set its bounds to {0, y1, screenWidth, y2}

else

set {x1, y1, null, y2} to (get its bounds)
set newBounds to {x1, y1, x1 + newWindowWidth, y2}
set its bounds to newBounds

tell newBounds
set winWidth to (its item 3) - (its item 1)
end tell

set winPos to its position
set newXPosition to round ((screenWidth - winWidth) / 2)
set item 1 of winPos to (newXPosition - 64) -- I like a 
left offset.
set its position to winPos

end if

end tell
end tell

-

Re: Stumped on this one

2021-06-15 Thread Christopher Stone
On 06/15/2021, at 18:28, @lbutlr mailto:krem...@kreme.com>> 
wrote:
> I have a file that has a few hundred lines, 77 of which are a HTML/XML style 
> date element
> 
> Tue, 15 Jun 2021 17:12:26 -0600
> 
> I have another files that has 77 date lines in the same format. Everything is 
> different dates, obvs.
> 
> I want to replace the first date in file 1 with the first date in file 2, and 
> so on through the entire file.


Hey Lewis,

I think what I'd do is:

1) Scrape the file 1 for the replacement date lines.

2) Paste them into this script in place of the dummy $input items:


#!/usr/bin/env perl -sw
use v5.010;

my $input = '
Tue, 01 May 2021 17:12:26 -0600
Tue, 02 May 2021 17:12:26 -0600
Tue, 03 May 2021 17:12:26 -0600
';

$input =~ s!\A\s+|\s+$!!g;

my @array = split(/\n/, $input);

my $counter = 0;

while (<>) {
   
   if (m!.+?!) {

  s!.+?!$array[$counter]!;
  $counter++;
  print;
  
   } else {

  print;

   }
   
}


3) Open the file where the replacements are to take place to be frontmost in 
BBEdit.

4) Run the script.

It works well on my test file (only lightly tested).


If I had more time and was feeling adventurous I'd do basically the same thing, 
except:

1) My user-input would be the source and destination file paths.

2) I'd read the source file date items directly into an array.

3) Then I'd open the destination file and do the processing in-place.

I haven't played with reading and writing files for a while, so that's more 
than I want to tackle at the moment.


--
Take Care,
Chris


-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/EE1628F6-0087-49A4-92D7-CAAC7B4385F4%40gmail.com.


Re: Extract number within parentheses using GREP

2021-06-07 Thread Christopher Stone
On 06/07/2021, at 14:53, Christopher Stone <listmeister...@gmail.com> wrote:This becomes terribly tedious when you do it all by hand, so I wrote you an example Text Factory.Install here:~/Library/Application Support/BBEdit/Text Filters/Text Factories/You have to run it from the Text > Apply Text Filter menu with the target document FRONTMOST.Hey Howard,Oops...  I sent you the wrong Text Factory.  That one works but is less precise than this one.--Take Care,Chris



-- 
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/2DFBE0DB-4D49-4C0A-802C-AE09B96D8396%40gmail.com.
<>




-- 
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/2DFBE0DB-4D49-4C0A-802C-AE09B96D8396%40gmail.com.


Re: Extract number within parentheses using GREP

2021-06-07 Thread Christopher Stone
On 06/03/2021, at 09:46, Howard  wrote:Chris, what you wrote is very helpful.To get the Grep results not enclosed in parentheses, I used the Replace pattern `\2` with this Search pattern:\d*(\((\d+)\))\d*but that resulted in these numbers:10161011Hey Howard,That can't be right.  If you genuinely got the above result you need to show all your steps.In BBEdit 12 and 13:Source:(10)0(16)500021(10)(11)Find: `\d*(\((\d+)\))\d*`Repl: `\2`Result:10161011The above would be better written this way:Source:(10)0(16)500021(10)(11)Find: `\d*\((\d+)\)\d*`Repl: `\1`Result:10161011To get the output you want add a space to `\1 `You'll get:10161011Follow that up by removing the trailing horizontal whitespace.Find: `\h+$`Repl: nothingThis becomes terribly tedious when you do it all by hand, so I wrote you an example Text Factory.Install here:~/Library/Application Support/BBEdit/Text Filters/Text Factories/You have to run it from the Text > Apply Text Filter menu with the target document FRONTMOST.Give it a keyboard shortcut for convenience in BBEdit's Menus & Shortcuts prefs.Text Factories let you do quite a lot without learning how to write scripts.--Take Care,Chris



-- 
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "supp...@barebones.com" rather than posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/3480DA58-0FBC-4F72-99EC-9C25C868986E%40gmail.com.
<>




-- 
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "supp...@barebones.com" rather than posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/3480DA58-0FBC-4F72-99EC-9C25C868986E%40gmail.com.


Re: Extract number within parentheses using GREP

2021-06-02 Thread Christopher Stone
On 06/01/2021, at 18:59, Howard mailto:leadwithlo...@gmail.com>> wrote:
> To help me to understand better the Grep part of Neil's solution, can someone 
> provide me with the search pattern and the replace pattern to just find those 
> lines with numbers in parentheses and extract them without any line numbers? 
> I'd like to put that into the Pattern Playground and work with that a bit.


Hey Howard,

Assuming all of your data lines are variations of this format:

1001405001
(10)
00132001
0(16)500
021(10)(11)
010101000

Then it's extremely simple to extract the lines.

Find:

.*\(\d+\).*

.*   ==  any character zero or more.
\(   ==  literal open parenthesis.
\d+  ==  any digit one or more.
\)   ==  literal close parenthesis.
.*   ==  any character zero or more.


If I knew that any line containing even 1 parenthesis was viable for extraction 
I could be lazy and do:

Find:

.*\(.*

.*   ==  any character zero or more.
\(   ==  literal open parenthesis.
.*   ==  any character zero or more.

OR

You could use Neil's suggestion of Process-Lines-Containing with just 1 literal 
parenthesis.


Now – to remove the unwanted digits:

Find:

\d*(\(\d+\))\d*

\d*  ==  any digit zero or more.
(==  start capture group.
\(   ==  literal parenthesis.
\d+  ==  any digit 1 or more.
\)   ==  literal parenthesis.
)==  close capture group.
\d*  ==  any digit zero or more.

Replace:

\1

\1   ==  capture group 1.


As I've mentioned BBEdit is always my starting point for building regular 
expressions, but there are times when a tool like RegEx101.com 
 will give you more information and more explanation.

See your patter here:

https://regex101.com/r/eUm1Fo/1 

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/95FE0CE0-CDBE-4044-A1CB-C4FAD1A7F1A2%40gmail.com.


Re: Extract number within parentheses using GREP

2021-06-01 Thread Christopher Stone
On 06/01/2021, at 08:11, Howard mailto:leadwithlo...@gmail.com>> wrote:
> I have a set of numbers. Within some of them is at least one number within 
> parentheses. I need to find all the lines containing numbers within 
> parentheses and extract those numbers. I also need to know which line they 
> are extracted from.


Hey Howard,

Bash text filter:

#!/usr/bin/env bash
nl -n ln | sed -En 's![0-9]*(\([0-9]+\))[0-9]*!\1!p;'

Result:

2   (10)
4   (16)
5   (10)(11)

I've left on the parentheses to make it clear when there are more than one set 
in a line.


If we're going to resort to Perl we might as well go all in:

#!/usr/bin/env perl -sw
while (<>) {
   if ( m!\(\d+\)! ) {
  s!\d*(\(\d+\))\d*!$1!g;
  print "$.\t" . $_;
   }
}

Result:

2   (10)
4   (16)
5   (10)(11)

Or just to be a bit cheeky:

#!/usr/bin/env perl -sw
while (<>) { if ( m!\(\d+\)! ) { s!\d*(\(\d+\))\d*!$1!g; print "$.\t" . $_; } }

OR

#!/usr/bin/env bash
perl -wlne '{if(m!\(\d+\)!){s!\d*(\(\d+\))\d*!$1!g;print"$.\t".$_;}}'



Don't forget – you can extract text directly from the front document using the 
Find Dialog and the [Extract] button.

1) Number lines.
2) Extract lines to new doc (with Find Dialog).
3) Find/replace to leave only the desired text.

The same as Neil's suggestion but without using Process Lines Containing.

TMTOWTDI.

I generally prefer using a text filter for this sort of thing, and I have one 
that opens with a hotkey and runs via another hotkey. So writing a filter and 
running it usually takes me less time than running through the steps with 
BBEdit's other tools.  ( Usually but not always... :)

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/74CC204B-F53A-4EC0-8C2B-60CF212C16CE%40gmail.com.


Re: AppleScript to make window wide enough to not scroll?

2021-06-01 Thread Christopher Stone
On 05/31/2021, at 08:27, TJ Luoma mailto:luo...@gmail.com>> 
wrote:
> I had a feeling you'd know the answer to this one… because you had already 
> written it :-)
> 
> Unfortunately I'm getting an error that I don't understand at all. I pasted 
> the full message here 


Hey TJ,

Okay, here's a revised script that's working on Mojave with BBEdit 13.5.6.

I believe the changes I made should make the script viable through Big Sur, but 
I can't be certain without testing.

I bias my windows slightly left-of-center.  If you want to completely center 
then look for a comment with “comment-out” in the script and follow the 
instructions.

The window is not quite shrunken to it's minimal proportions with BBEdit 13.x – 
it's a few pixels off.  I assume this is because the UI element widths I used 
for BBEdit 12.x are a bit different in v13, but I haven't bothered to tweak it 
as yet.

See the values for:

gutterWidth
gutterPad
scrollbarWidth

Adjust as needed.

Enjoy.

--
Take Care,
Chris

-------
# Auth: Christopher Stone { Kudos to Shane Stanley for his generous help with 
ASObjC }
# dCre: 2018/09/16 22:24
# dMod: 2021/06/01 13:47
# Appl: BBEdit
# Task: Resize width of front BBEdit window according to longest line and 
center.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @BBEdit, @Resize, @Width, @Front, 
@Window, @Longest, @Line, @Center
---
use AppleScript version "2.7" -- macOS 10.14 or later
use framework "Foundation"
use framework "AppKit"
use scripting additions
---
property fontName : "Inconsolata-g"
property fontSize : "16.0"
---

set screenWithMenu to current application's NSScreen's screens()'s 
objectAtIndex:0
set screenWithMenuFrameSize to (screenWithMenu's frame())
set screenHeight to (item 2 of (item 2 of screenWithMenuFrameSize)) as integer
set screenWidth to (item 1 of (item 2 of screenWithMenuFrameSize)) as integer

set maxLineLength to 0
set maxLineContent to missing value

tell application "BBEdit"
tell front text window
repeat with theLine in its lines
if (length of theLine) > maxLineLength then
set maxLineLength to (length of theLine)
set maxLineContent to (contents of theLine)'s contents
end if
end repeat
end tell
end tell

set theFont to current application's NSFont's fontWithName:fontName 
|size|:fontSize
set theAtts to current application's NSMutableDictionary's ¬
dictionaryWithObject:theFont forKey:(current application's 
NSFontAttributeName)

set atrString to (current application's NSAttributedString's alloc()'s 
initWithString:maxLineContent attributes:theAtts)
set theSize to atrString's |size|()
set lineWidth to round (width of theSize)

if lineWidth < 400 then
error "Text content is too narrow to resize the window!"
end if

set gutterWidth to 64
set gutterPad to 18
set scrollbarWidth to 16
set newWindowWidth to lineWidth + gutterWidth + gutterPad + scrollbarWidth

tell application "BBEdit"
tell front window

if newWindowWidth > screenWidth then
set {null, y1, null, y2} to (get its bounds)
set its bounds to {0, y1, screenWidth, y2}
else

set {x1, y1, null, y2} to (get its bounds)
set newBounds to {x1, y1, x1 + newWindowWidth, y2}
set its bounds to newBounds

tell newBounds
set winWidth to (its item 3) - (its item 1)
end tell

set winPos to its position
set newXPosition to round ((screenWidth - winWidth) / 2)

# Comment-out this line if you want the window perfectly centered.
set item 1 of winPos to (newXPosition - 64) -- I like a left offset.

set its position to winPos

end if

end tell
end tell

---

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/838485BA-F062-4372-BDB7-5FC8601055AD%40gmail.com.


Re: AppleScript to make window wide enough to not scroll?

2021-05-31 Thread Christopher Stone
On 05/30/2021, at 17:14, TJ Luoma mailto:luo...@gmail.com>> 
wrote:
> Hi all, my name is TJ and I don't understand AppleScript, hence I come, 
> again, asking for help from those who do.
> 
> I like to set "Soft Word Wrap" to "Window Width".
> 
> But then I often find that I want to adjust the width of the window so that 
> it is _just_ wide enough to not need a horizontal scroll bar.
> 
> Tonight it occurred to me that this would be a good place for automation, but 
> I can't figure out if that's possible, and Google is no help because it just 
> tells me how to change word wrap or other word-wrap related things that are 
> not the thing I'm looking for.


Hey TJ,

There's probably only one place on the whole Internet to find that.

https://forum.latenightsw.com/t/resize-width-of-front-bbedit-window-according-to-longest-line-and-then-center/1531
 


The original script works for me on macOS 10.12.6 Sierra, but there's a change 
to AppleScript in High Sierra that has to be adjusted for.

Rich kindly added sidebar width to BBEdit's AppleScript lexicon after I wrote 
this, but I have not (as yet) changed the script to adapt to its open/closed 
state.

Presently the script expects the sidebar to be closed when run.

If you can't follow the thread and get it running on your system let me know.  
I can reproduce the issue on my MacBook Air (Mojave), so I should be able to 
fix it without too much trouble.

If I have time I might look at it late Monday.


--
Take Care,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/11C1632C-D694-402A-9E53-8E44B07923A3%40gmail.com.


Re: Two files in the same window

2021-05-27 Thread Christopher Stone
On 05/27/2021, at 11:16, Ron Catterall mailto:roncattera...@gmail.com>> wrote:
> Heresy I know: BUT Supreme Text will do 2, 3 ...side by side same or 
> different files


Hey Ron,

Did you mean Sublime Text 
?

Hey Jan - this feature has been requested before and not gotten any traction at 
all so far as I know.

If you really want it you should make a good case and send it to support.

Bare Bones Software mailto:supp...@barebones.com>>


--
Take Care,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/69C229A6-C76A-414D-AF33-9A7C234B2EB9%40gmail.com.


Re: Handling dollar signs in search and replace

2021-05-27 Thread Christopher Stone
On 05/26/2021, at 21:42, Duncan Thorne mailto:duncan...@gmail.com>> wrote:
> I just noticed that you too use T-E+. I sing the praises of it every day and 
> it's a big reason I'm still at Mojave, the last 32-bit compatible version of 
> the OS. I wonder what happened to Tom Bender, the guy behind it. I've found 
> no answer on Google.


Hey Duncan,

I sent Tom a Christmas card in 2018 and had a brief email correspondence with 
him.

It's the usual story – he got a job, had a family, and got busy...  :-)

In my opinion the only really viable replacement for Tex-Edit Plus is Jedit Ω 
.

It doesn't have quite as organic a feel as Tex-Edit Plus, but it's similarly 
powerful and relatively simple.


--
Take Care,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/1A9EF0CB-9150-4936-9E11-3B331BAEA1A3%40gmail.com.


Re: Handling dollar signs in search and replace

2021-05-26 Thread Christopher Stone
On 05/25/2021, at 23:19, Duncan Thorne mailto:duncan...@gmail.com>> wrote:
> Here's a sample line from my script where things go wrong:
> tell front text window's text
> 
> replace "2021
> 
> \$" using "   \$" options {search mode:grep, case sensitive:false, starting 
> at top:true} -- the idea being to take out a line break and replace it with a 
> tab.
> 
> end tell
> 


Hey Duncan,

Backslash is the escape character in AppleScript, so when you need to write it 
as a literal you have to escape the escape character.

set myDollarSign to "\\$"

I know this is often quite confusing to neophyte AppleScripters, so please 
forgive me for forgetting to mention it explicitly.

For future references here's how you'd write the regular expression in 
AppleScript:

tell application "BBEdit"
tell front document
replace "(2021)\\n(\\$)" using "\\1\\t\\2" options {search mode:grep, 
case sensitive:false, starting at top:true}
end tell
end tell

If you take the literal strings (between the quotes) and replace the "\\" with 
"\" as a literal string in BBEdit you'll get unescaped version that BBEdit 
wants.

A perhaps simpler trick to see the literal string is to copy it to the 
clipboard like so:

set the clipboard to "(2021)\\n(\\$)"

--> (2021)\n(\$)

The part after “--> ” is the pasted result.

“--> ” is a writing convention for indicating the result of an AppleScript.

I too am a long time user of Tex-Edit Plus and will sorely miss it down the 
road.


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/1D99E910-A13C-4F44-A723-43F76A17DE93%40gmail.com.


Re: Handling dollar signs in search and replace

2021-05-25 Thread Christopher Stone
On 05/25/2021, at 19:17, Duncan Thorne mailto:duncan...@gmail.com>> wrote:
> I'm stumped when it comes to reformatting a text line that begins with a $ 
> symbol. I want to replace the preceding line's line break, followed by the 
> new line's $, with a tab-$.
> For instance:
> ... 2021
> $0.23
> 
> changed to:
> ... 2021 (tab) $0.23


Hey Duncan,

Look in Chapter 8 of BBEdit's User Manual: Searching with Grep (p182)

(Available from the BBEdit Help Menu.)

$ is a regex metacharacter referred to as an anchor, and it indicates the end 
of a line.

^ (the caret character) refers to the beginning of a line.

As Kerri mentions you escape these characters when using them literally.  (This 
takes a little getting used to.)

\ (backslash) is the usual escape character so – \$ and \^

Find:

\n^(\$\d+)


\n  == linefeed
^   == beginning of line
(   == start of capture group)
\$  == literal dollar sign character
\d  == digit
+   == one or more
)   == end of capture group

Replace:

\t\1


\t == literal tab
\1 == capture group 1

This is your basic regular expression.


A more advanced regular expression using a positive lookahead assertion:

Find:

\n(?=\$)


\n  == linefeed
(   == start of a NON-capture group
?=  == lookahead assertion which looks for a string without selecting it
\$  == literal dollar sign
)   == close of the non-capture group

Replace:

\t


\t == literal tab

With this method and your use-case I don't have to capture any text and put it 
back; I can just replace the found text with a tab.

Many people think regular expression are cruel and unusual punishment, but I 
enjoy them – they're fun (and sometimes also frustrating) puzzles to solve.  

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/A4B22EA0-D109-4D69-8203-C6700A9622FC%40gmail.com.


Re: Finding & replacing text with Applescript

2021-05-25 Thread Christopher Stone
On 05/24/2021, at 21:44, Rich Siegel mailto:sie...@barebones.com>> wrote:
> This is a good script. Some feedback: as a matter of best practices and 
> future proofing, avoid targeting windows (or elements of them).


Hey Duncan,

Here's the script using Rich's suggested best practices.

I'm using the top table on this page as my test data:

https://material.angular.io/components/table/examples 
<https://material.angular.io/components/table/examples>


--
Best Regards,
Chris

----
# Auth: Christopher Stone mailto:scriptmeis...@thestoneforge.com>>
# dCre: 2021/05/24 21:24
# dMod: 2021/05/25 17:04
# Appl: BBEdit
# Task: Copy Safari Table to New BBEdit Document and Find-Replace.
# : (Following Best Practices)
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Table, @RegEx, @Massage, @Data
# Vers: 1.50


set jsCmdStr to "

(() => {
return window.getSelection().toString()
})();

"
set tableContent to doJavaScriptInSafari(jsCmdStr)

tell application "BBEdit"
activate

set newDoc to make new text document with properties {text:tableContent}

# Resize and reposition the new document.
# {x1, y1, x2, y2} Upper-Left-Corner, Lower-Right-Corner.
set bounds of front window to {0, 45, 1314, 1196}

tell newDoc
replace "Carbon|Helium" using "••" options {search mode:grep, case 
sensitive:false, starting at top:true}
end tell

end tell


-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/47581AFF-A968-4C3A-958E-FD6F60DA28C6%40gmail.com.


Re: Line breaks: How to avoid them?

2021-05-25 Thread Christopher Stone
On 05/25/2021, at 13:58, Duncan Thorne mailto:duncan...@gmail.com>> wrote:
> At the end of each of my find-and-replace applescript lines, for massaging 
> text, the result includes an unwanted line break. Is there a way to avoid 
> this?


Hey Duncan,

What's your script?

Please show an example of your problem including a before and after sample.


--
Best Regards,
Chris


-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/8A4FC27E-CB5F-4CF6-A2D6-5A34E3910B95%40gmail.com.


Re: Finding & replacing text with Applescript

2021-05-24 Thread Christopher Stone
On 05/24/2021, at 21:44, Rich Siegel mailto:sie...@barebones.com>> wrote:
> his is a good script. Some feedback: as a matter of best practices and future 
> proofing, avoid targeting windows (or elements of them).


Hey Rich,

Thanks for the feedback.

Actually I often use this sort of construct:


tell application "BBEdit"
activate
set myDoc to make new text document with properties {text:"some text"}
return myDoc
end tell

--> text document 1 of application "BBEdit"


What I don't like about it is the reference it creates – it will break if you 
change the window index in the script and then refer to the reference again.


Getting a reference to any document besides document 1 produces a more sturdy 
reference:

tell application "BBEdit"
set docRef to document 2
end tell

--> project document "untitled project 45" of application "BBEdit"


If I need the reference to be more robust I have to do something like this:

tell application "BBEdit"
activate

set docID to ID of (make new document with properties {text:"some text"})

tell document id docID
set after its text to linefeed & "some more text" & linefeed
select insertion point after its text
end tell

end tell

Most of the time working with the front document is perfectly adequate – but 
not always.


--
Take Care,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/89BBA9CA-23BE-4A42-BEE0-063A77475A28%40gmail.com.


Re: Finding & replacing text with Applescript

2021-05-24 Thread Christopher Stone
On 05/24/2021, at 19:11, Duncan Thorne mailto:duncan...@gmail.com>> wrote:
> I'm pretty clueless with Applescript so please bear with me. I want to copy 
> text from a Safari table, paste it into a new BBEdit window and do some text 
> manipulation, mostly finding and replacing.


Hey Duncan,

This task is pretty simple if you know how, and a real head-scratcher if you 
don't.

It's great to be able to record AppleScript, but it often produces semi-useless 
results – unless you savvy AppleScript enough to be able to rewrite the 
recording and pick out the good bits.

I almost never use it, BUT it sometimes comes in really handy when I just can't 
figure out the syntax for something.

Appended is a script that will:

- Copy the selected text in Safari.
- Create a new BBEdit document with said text.
- Reset the size and position of the new document.
- Do one regex-based find/replace on the document.
- You can add more replace statements as needed.

Enjoy.

--
Best Regards,
Chris

----
# Auth: Christopher Stone
# dCre: 2021/05/24 21:24
# dMod: 2021/05/24 21:29
# Appl: BBEdit
# Task: Copy Safari Table to New BBEdit Document and Find-Replace.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Table, @RegEx, @Massage, @Data


set jsCmdStr to "

(() => {
return window.getSelection().toString()
})();

"
set tableContent to doJavaScriptInSafari(jsCmdStr)

tell application "BBEdit"

activate

make new text document with properties {text:tableContent}

# Resize and reposition the new document.
# {x1, y1, x2, y2} Upper-Left-Corner, Lower-Right-Corner.
set bounds of front window to {0, 45, 1314, 1196}

tell front text window's text
replace "Carbon|Helium" using "••" options {search 
mode:grep, case sensitive:false, starting at top:true}
end tell

end tell


--» HANDLERS

on doJavaScriptInSafari(jsCmdStr)
try
tell application "Safari" to do JavaScript jsCmdStr in front 
document
on error e
error "Error in handler doJavaScriptInSafari() of library NLb!" 
& return & return & e
end try
end doJavaScriptInSafari


-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/137F6908-E277-4388-BAB0-5E0B9A3A4E55%40gmail.com.


Re: Grep find/replace numbers

2021-05-24 Thread Christopher Stone
On 05/22/2021, at 19:22, severdia mailto:sever...@gmail.com>> wrote:
> Yes, you're right. I got it working, but for future reference here's what I 
> was trying to do...I have many of these elements:
> 
> Macbeth5.15.1.64
> 
> Both  and  contain act/scene/line number info and either one other 
> the other is incomplete (the one with two numbers) and I want to keep the one 
> that's complete (with three numbers). My objective was to delete either  
> or  if it had only two numbers in it.


Hey Ron,

Explaining your actual task is quite helpful – but I always want to see 
examples of the start condition and the desired outcome in black and white.  

Like so:

Data Sample 01:

Macbeth5.15.1.64

Desired Outcome 01:

Macbeth5.1.64

You wouldn't believe how often people leave out or otherwise mangle 
instructions.  The "A picture is worth a thousand words." rule is highly 
relevant with this sort of task.

Here's what I would do:

Find:

\d+\.\d+

Replace with nothing.

With  I'm finding a digit that may ore may not exist and I'm using 
that capture in the closing tag .  This covers any loc tag from 0-9.

This is a trifle simpler and more direct (if there are only  and  
tags).

\d+\.\d+

While we're on the topic of data massage with regex, let me recommend this site 
to you:

https://regex101.com/r/WtIAmE/3  (This link 
contains your example problem.)

When I'm working on complex regular expressions I always start with BBEdit, but 
if I have substantial problems I have some regex visualizer apps (RegExRx 
 in particular) and 
RegEx101.com  to fall back on.

I can't use BBEdit 13's new Pattern Playground on my main Mac, because Sierra 
isn't supported.

One reason to look forward to getting new hardware...

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/7FB473E5-2467-4D8D-BE44-2351216E4B49%40gmail.com.


Re: Grep find/replace numbers

2021-05-22 Thread Christopher Stone
On 05/22/2021, at 10:50, severdia mailto:sever...@gmail.com>> wrote:
> I can't seem to figure out a way to find and replace some numbers using Grep. 
> This is what I have.
> 
> 2.22.2.93
> 
> I have many cases where there are 3 numbers separated by two periods wrapped 
> in  (like this: 2.2.309) as well as the example above with 2 
> numbers separated by 1 period wrapped in . I want to find where there 
> are only two numbers and delete that  element. For example I tried:


Hey Ron,

Explanations are welcome, but when asking for assistance with data manipulation 
it's best to provide concrete, real-world data samples and the expected results.

Words nearly always include assumptions and opportunities for error.

A good test case (or three) along with the expected result(s) makes it much 
easier for people to experiment and get the job right the first time.

If I'm understanding your task correctly then this should work:

Find:

(\d+\.\d+)

Replace:

\1


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/CCD1E1E9-D097-4FC1-A639-66BACD41C1BF%40gmail.com.


Re: Automator actions and Grep: Extracting lines

2021-05-19 Thread Christopher Stone
On 05/19/2021, at 08:30, Miguel Perez mailto:maperezespin...@gmail.com>> wrote:
> On a daily basis I get an XML file. This file contains information about some 
> dossiers. I need to extract two elements from each dossier: (1) a URL to 
> download associated images, and (2) the dossier's name.


Hey Miguel,

I don't think that automator action will take a file as input, but I'm not 
absolutely certain.

In any case I think you should bite the bullet and learn a little more shell 
scripting – since you're already using wget.

I'm just playing around here a bit to show you what's easily accomplished.

You can run these conveniently in a BBEdit worksheet to see what they do.


filePath=~/Downloads/MA_NO_2021_05_011.xml

# Prints the found pattern in the given text file.
grep -E -o -e 'http.+ImagenFichaServlet[^]]+' "$filePath"


filePath=~/Downloads/MA_NO_2021_05_011.xml

# Prints the line after the found pattern along with the found text.
grep -E -A 1 -o 'Denominación' "$filePath"


filePath=~/Downloads/MA_NO_2021_05_011.xml

# Prints the line after the found pattern then deletes the detritus.
sed -n '/Denominación/{n;p;}' "$filePath" \
| sed -E 's!.+\[|\].+!!g'


The output of these is easily redirected to files.

Your wget downloader can follow the extract-text segments.

You can rename your files using wget itself, or you can follow-on with a rename 
script.

Personally I'd do all of this in Bash.

That said let me recommend Keyboard Maestro 
 to you as a great tool for getting real 
work done on a Mac. In my expert opinion it's currently the Best-of-Breed Mac 
Automation Utility. (Commercial  $36.00 US.)

It's a bit like Automator on steroids, and I've been a happy superuser for 
about 17 years now.

Like BBEdit it runs 24/7 on my Macs.

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/300572B7-45BA-4BE0-912E-41060D2DADF8%40gmail.com.


Re: Moving endnotes to inline

2021-05-14 Thread Christopher Stone
On 05/14/2021, at 14:04, Cooper Cavalier mailto:dstromber...@gmail.com>> wrote:
> I have a text/html file which has thousands of endnotes.  The file has the 
> inline endnote reference as [1], [2], [3], etc. which correspond to the 
> appropriate endnote.  For the app publisher I am working for, the endnotes 
> must be placed in line with specific coding.
> 
> I am totally stumped in finding a way either inside of Bbedit or using a 
> Python script.  I am doing this editing on a Mac.


Hey Doug,

If I've understand correctly all footnote references are going to look like: 
_ftn18 and [18].

What think I would do is (without having seen the full scope of the problem):

A) Split off all of the footnotes into their own file.

B) Write a regular expression or a script to massage all of the footnotes into 
their new format.
 - Leaving the footnote reference as a prefix to the new reference.
 - Make sure each footnote is formatted such that they all may be easily 
read into an array.

C) Read the footnotes into an array (in Perl for me).

D) Iterate through the array and find the matching footnote ref in the body 
document.
 - Make the appropriate substitutions.


Another alternative (for me) would be to do the job with BBEdit and AppleScript 
using the same general methodology, except that I'd use the page of footnotes 
as the array.

Pros:

  - Easier to prototype and visualize.

Cons:

  - Much slower execution time.

--
Best Regards,
Chris
/

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/490C80DA-9C16-46CC-93A6-6CF919B207E8%40gmail.com.


Re: Need help accessing multiple files' content at the same time

2021-05-08 Thread Christopher Stone
On 05/07/2021, at 17:10, @lbutlr mailto:krem...@kreme.com>> 
wrote:
> On 07 May 2021, at 05:32, Christopher Stone  <mailto:listmeister...@gmail.com>> wrote:
>> # Find files, concatenate their contents, send result to BBEdit.
>> find -E . -type f \( ! -name ".*" \) -exec sed -n '1,$p' {} \; | bbedit
> 
> OK, two questions.
> 
>  1) why -E?
>  2) '1,$p'?
> 
> Where/what is $p?


Hey Lewis,

Well, -E isn't really necessary in this use-case.  I have it in my template for 
find, because I often use a regular expression and always want to use the 
Extended regular expression set.

> sed -n '1,$p'

This is just `sed` printing from line 1 through the last line of the given file.

And actually that can be reduced to just p for print:

sed -n 'p'

So this works perfectly well:

find -E . -type f \( ! -name ".*" \) -exec sed -n 'p' {} \; | bbedit

I was going to use `cat` for this task, but `sed` will add an ending line break 
if there isn't one already in the printed file and `cat` won't.

Sed:

file01contents
file02contents
file02contents

Cat:

file01contentsfile02contentsfile02contents


--
Take Care,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/D8354D3D-7404-4D83-A23B-4F2168447208%40gmail.com.


Re: Need help accessing multiple files' content at the same time

2021-05-07 Thread Christopher Stone
On 05/06/2021, at 10:06, Howard mailto:leadwithlo...@gmail.com>> wrote:
> Patrick, your way of concatenating individual files works well.
> 
> I have a folder that contains both folders whose contents I would like to 
> include in the concatenation as well as separate individual files. Is there a 
> way to do that in BBEdit?


Hey Howard,

If you're going to do this regularly you might want to systematize the process.

Place the following script in:

~/Library/Application Support/BBEdit/Scripts/


#!/usr/bin/env bash
# -----
# Auth: Christopher Stone
# dCre: 2021/05/07 06:07
# dMod: 2021/05/07 06:07 
# Task: Recursively Concatenate Files in the Front Finder Window.
# Tags: @ccstone, @Shell, @Script, @Concatenate, @Files, @Finder, @BBEdit
# -

# Acquire the path to the Front Finder Window. (Finder Insertion Location.)
read -r -d '' asCmdStr <<'EOF'
   tell application "Finder"
  set targetFolder to insertion location as alias
  return POSIX path of targetFolder
   end tell
EOF
targetFolderPath=$(osascript -e "$asCmdStr")

# Change the working directory to the Finder Insertion Location.
cd "$targetFolderPath"

# Find files, concatenate their contents, send result to BBEdit.
find -E . -type f \( ! -name ".*" \) -exec sed -n '1,$p' {} \; | bbedit


Give it a memorable name.

If desired give it a keyboard shortcut in BBEdit's Menus & Shortcuts 
Preferences.


REQUIREMENTS:

BBEdit's command line tools must be installed.



USAGE:

1) Open the desired target directory in the Finder, so its window is FRONTMOST.

2) Run the script from BBEdit's Script menu or via a keyboard shortcut.


RESULT:

A new window will be opened in BBEdit containing the concatenated contents of 
every file in the target directory (recursive).


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/6C639B20-5E85-4D55-AF42-0A2B82EB1B21%40gmail.com.


Re: Trying to remove all empty lines with this grep isn't working

2021-04-27 Thread Christopher Stone
On 04/26/2021, at 18:37, David J mailto:futurevint...@gmail.com>> wrote:
>  I'm trying to take out any empty lines from a document and can't figure out 
> why it's not working. 
> 
> I'm adding the text, then selecting all then adding grep
> 
> ^\s*?\r  
> 
> then replace all with nothing. I'm getting "not found" on any document. 
> Weirdly, I swear this was working before. Can anyone give some insight here?


Hey David,

Why are you selecting-all?

Adding grep where?

Your pattern above works with normal text and blank lines.

Although I would use a capital R to represent more types of line endings:

^\s*?\R

The fact nothing is working for you might be explained by:

1) You've turned OFF [ ] Grep in the Find dialog.

2) You are selecting-all and then using Cmd-G to try to find without 
Wrap-Around active.

Another thing – blank lines are often NOT blank.  Very frequently some 
whitespace has crept in that needs to be accounted for, and it is also common 
for normal lines to have accidental trailing whitespace.

So – I would manage this be removing any trailing whitespace and blank lines at 
the same time:

Find:

\h*\v\s+

Replace:

\n

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/CF3AB8A5-026E-46EB-8638-B5FAA450E08E%40gmail.com.


Re: find first x of a ',' delimited set of numeric strings?

2021-04-27 Thread Christopher Stone
On 04/26/2021, at 12:53, Joel Braverman mailto:joeljbr...@gmail.com>> wrote:
> have a few thousand of these: 
> '199','627','1151','1249','1557','1558','1565','1689','1693','1711','1770','1780'
> 
> I want to break them up into subgroups as our SQL system chokes at > 4000 
> items in a query.


Hey Joel,

Find:

(?:'[^']+',){4000}

Replace:

&\n

Since you're dealing with pretty big chunks of data, I'd turn capturing off 
with (?: as above.

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/5A42303B-DCD4-41A0-ACF9-59E32566E47A%40gmail.com.


Re: Sorting transcripts

2021-04-26 Thread Christopher Stone
On 04/25/2021, at 00:34, @lbutlr mailto:krem...@kreme.com>> 
wrote:
> On 19 Apr 2021, at 21:46, Christopher Stone  <mailto:listmeister...@gmail.com>> wrote:
>> use v5.010;
> 
> Excellent script, but is this needed? And what are the consequences if you 
> have 5.32 installed?


Hey Lewis,

Thank you.

No, use v5.010; is not required in this case.

It does not designate the Perl version used per se – it does designate the 
lowest possible version of Perl that can be used.

I frequently set the lowest version to 5.010, because it allows `say` to be 
used in addition to `print`.  (Without the use statement `say` will throw an 
error.)

You can run this to demonstrate to yourself that your current Perl version is 
the one being used.


#!/usr/bin/env perl -sw
use v5.010;

print "Perl $^V\n";


Appended is a slight mod of my script – I hadn't made the strip vertical 
whitespace code global, and under certain circumstances that could lead to an 
extra linefeed between a couple of dialog blocks.

I also added a regex to normalize the spacing between dialog blocks just for 
good measure.

--
Best Regards,
Chris


#!/usr/bin/env perl -0777 -nsw
# 
--------
# Auth: Christopher Stone
# dCre: 2012/11/27 08:12
# dMod: 2021/04/26 00:07
# Task: Sort CC Script Segments for a Video.
# Tags: @ccstone, @Shell, @Script, @CC, @Sort, @Video
# 

# use v5.010;

s!^LOGGER\h*\d+\h*!!gim;# Remove “Logger ##” lines if necessary.
s!^\h+|\h+$!!gm;# Remove trailing whitespace on every line.
s!\n{2,}!\n\n!gm;   # Normalize spacing between script blocks.
s!\A\s+|\s+\Z!!g;   # Remove leading and trailing vertical 
whitespace.
my @array = split(/\n\s+/, $_); # Split script segments into an array.
chomp(@array);  # Remove trailing linefeeds from records.
@array = sort(@array);  # Sort array.
$, = "\n\n";# Set Output Field Separator.
print @array;   # Print array.

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/52CE3E18-17C3-4AB1-AE8E-7C1F0DDAD191%40gmail.com.


Re: Using BBEdit for markdown presentation?

2021-04-20 Thread Christopher Stone
On 04/20/2021, at 14:31, Tibor Páli mailto:palitiborlas...@gmail.com>> wrote:
> Is TextsQuickLook.qlgenerator a script that you wrote, it is something 
> provided with Marked 2?
> Tibor
> 
>> I've got 3 apps on my system that include a Quick Look module for MarkDown.
>> 
>> com.barebones.bbedit.markdown-source -> 
>> /Applications/Applications_Chris/Markdown_Apps/Texts/Texts.app/Contents/Library/QuickLook/TextsQuickLook.qlgenerator
>>  (1.0)
>> 
>> net.daringfireball.markdown -> 
>> /Applications/Applications_Chris/Markdown_Apps/Texts/Texts.app/Contents/Library/QuickLook/TextsQuickLook.qlgenerator
>>  (1.0)
>> 
>> public.plain-text -> 
>> /Applications/Applications_Chris/Markdown_Apps/Texts/Texts.app/Contents/Library/QuickLook/TextsQuickLook.qlgenerator
>>  (1.0)
>> 
>> Quick Look can see Markdown files, and Spotlight can find their content.


Hey Tibor,

No, look more carefully at the listed apps.

I was mistaken – there are only two apps – BBEdit and Texts.app.  The Texts.app 
actually has two text flavors – plain text and markdown.

You can discover a few things about Quick Look by using the Terminal:

man qlmanage

qlmanage -m | egrep -i "markdown"

Texts.app (freeware) is a bit like Marked, but it's an editor – not just a 
viewer.

http://www.texts.io 

Unfortunately it hasn't been updated since 2016.

There're one or more 3rd party QL modules.  Here's one:

https://github.com/toland/qlmarkdown 

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/25DC3DE8-54A0-4839-8287-F96F76277460%40gmail.com.


Re: Using BBEdit for markdown presentation?

2021-04-20 Thread Christopher Stone
On 04/20/2021, at 12:23, Tibor Páli mailto:palitiborlas...@gmail.com>> wrote:
> So, if I force to open an .md file with Safari, it opens it as an un-rendered 
> markdown text file, just like BBEdit.
> 
> I think Chrome can render markdown files. I my install and try.


Hey Tibor,

Take a good look at Marked 2, before you spend much more time on this.


URL Handler

Marked’s URL handler provides additional scripting and workflow capabilities. 
You can include a url in the notes of another application, for example, that 
will open a file in Marked when clicked. You can perform several actions, as 
listed below.

https://marked2app.com/help/URL_Handler.html 





I've got 3 apps on my system that include a Quick Look module for MarkDown.

com.barebones.bbedit.markdown-source -> 
/Applications/Applications_Chris/Markdown_Apps/Texts/Texts.app/Contents/Library/QuickLook/TextsQuickLook.qlgenerator
 (1.0)

net.daringfireball.markdown -> 
/Applications/Applications_Chris/Markdown_Apps/Texts/Texts.app/Contents/Library/QuickLook/TextsQuickLook.qlgenerator
 (1.0)

public.plain-text -> 
/Applications/Applications_Chris/Markdown_Apps/Texts/Texts.app/Contents/Library/QuickLook/TextsQuickLook.qlgenerator
 (1.0)

Quick Look can see Markdown files, and Spotlight can find their content.

--
Best Regards,
Chris


-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/D8700C86-CAEE-43F7-985A-A4267BAA764A%40gmail.com.


Re: Sorting transcripts

2021-04-19 Thread Christopher Stone
Hey James,

I'm late to this party, but I wanted to see how fun it would be to do the job 
in Perl.

It turned out to be really simple:


#!/usr/bin/env perl -0777 -nsw
# 

# Auth: Christopher Stone
# dCre: 2012/11/27 08:12
# dMod: 2021/04/19 21:36 
# Task: Sort CC Script Segments for a Video.
# Tags: @ccstone, @Shell, @Script, @CC, @Sort, @Video
# 

use v5.010;

s!^LOGGER\h*\d+\h*!!gim;# Remove “Logger ##” lines if necessary.
s!\A\s+|\s+\Z!!;# Remove leading and trailing vertical 
whitespace.
s!^\h+|\h+$!!gm;# Remove trailing whitespace on every line.
my @array = split(/\n\s+/, $_); # Split script segments into an array.
chomp(@array);  # Remove trailing linefeeds from records.
@array = sort(@array);  # Sort array.
$, = "\n\n";# Set Output Field Separator.
print @array;   # Print array.


Save the script in:

~/Library/Application Support/BBEdit/Text Filters/.pl

Give it a keyboard shortcut in BBEdit's Menus & Shortcuts preferences – or 
activate it from the Text > Apply Text Filter menu.

Note:

script segments must have at least 1 blank line between them.

--
Best Regards,
Chris


> On 03/11/2021, at 15:39, ajames  <mailto:ajameswar...@gmail.com>> wrote:
> 
> Complete novice here exploring an option for a workflow, thank you for the 
> help. Totally out of my area here.
> 
> Trying to combine on set television logging scripts into a master script. 2 
> seperate loggers concentrating on different talent, producing seperate 
> scripts e.g
> 
> LOGGER 1
> 
> [15:57:13.22]
> PRODUCER:
> WHERE ARE YOU FROM? 
> 
> [18:57:15:00]
> CONTESTANT 1:
> I'm from Austin Texas. Wait should I say
> 
> [18:57:16.13]
> PRODUCER:
> I THINK YOU SHOULD SAY AUSTIN AS ONE. YOU ARE EARING A COBOYS HAT. 
> 
> [15:57:27:03]
> CONTESTANT 2:
> Or should I say both? I'm from Austin but I live in Vegas. 
> 
> LOGGER 2
> 
> [15:57:14.22] 
> PRODUCER 2:
> TELL ME, TELL ME.
> 
> [15:57:15.22] 
> CONTESTANT 2: 
> I run the junior program at my country club, I help with event set ups and I 
> do all the retail buying for the country club.
> 
> [15:57:20.22] 
> PRODUCER 2:
> CAN WE NOW PUT YOUR INTRO ALL TOGETHER? SO YOU'RE BASICALLY IN ONE THOUGHT 
> 'MY NAME'S CONTESTANT 2, I'M FROM CALIFORNIA AND THIS IS WHAT I DO.'
> 
> [15:57:31.22] 
> CONTESTANT 2: 
> Okay, um. I'm contestant 2, I'm from California and I'm a golf shop manager 
> in New York.
> 
> I need to sort by combine these scripts into a single document for our edit 
> software to read, but I need to keep the spacing and format of each small 
> block of text, just need to sort by time e.g.
> 
> [15:57:13.22]
> PRODUCER:
> WHERE ARE YOU FROM? 
> 
> [15:57:14.22] 
> PRODUCER 2:
> TELL ME, TELL ME.
> 
> [18:57:15:00]
> CONTESTANT 1:
> I'm from Austin Texas. Wait should I say
> 
> [15:57:15.22] 
> CONTESTANT 2: 
> I run the junior program at my country club, I help with event set ups and I 
> do all the retail buying for the country club.
> 
> [18:57:16.13]
> PRODUCER:
> I THINK YOU SHOULD SAY AUSTIN AS ONE. YOU ARE EARING A COBOYS HAT. 
> 
> [15:57:20.22] 
> PRODUCER 2:
> CAN WE NOW PUT YOUR INTRO ALL TOGETHER? SO YOU'RE BASICALLY IN ONE THOUGHT 
> 'MY NAME'S CONTESTANT 2, I'M FROM CALIFORNIA AND THIS IS WHAT I DO.'
> 
> [15:57:27:03]
> CONTESTANT 2:
> Or should I say both? I'm from Austin but I live in Vegas. 
> 
> [15:57:31.22] 
> CONTESTANT 2: 
> Okay, um. I'm contestant 2, I'm from California and I'm a golf shop manager 
> in New York.

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/20FA4B04-D617-41A4-A324-7551AFE39AB8%40gmail.com.


Re: How to grep a list of hyperlink to capitalise the words

2021-04-19 Thread Christopher Stone
On 04/19/2021, at 09:21, Francisco Hirsch mailto:listas.hir...@gmail.com>> wrote:
> I should have made my question and example clearer.
> I give a clearer example:
> 
> 1. THIS SOFTWARE IS PROVIDED “AS IS”, WITHOUT
> 2. PERMISSION IS GRANTED TO ANYONE TO USE THIS


Hey Francisco,

In my script I've ensured that only hrefs containing "link<1 or more digits>" 
are affected.

This is easy to change of course.

--
Best Regards,
Chris


#!/usr/bin/env perl -sw
# Title Case Link Text
use v5.010;

my ($cap1, $cap2, $cap3);

while (<>) {

   if ( m!()(.+)()!i ) {

  ($cap1, $cap2, $cap3) = ($1, $2, $3);
  $cap2 =~ s!(\b\w[^\h[:punct:]]+)!\u\L$1!gi;
  say "$cap1$cap2$cap3";
  
   } else {
   
  print;
  
   }
   
}


-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/7D9BF37C-DC73-4686-9010-587A61BACE29%40gmail.com.


Re: How to grep a list of hyperlink to capitalise the words

2021-04-19 Thread Christopher Stone
On 04/19/2021, at 09:21, Francisco Hirsch mailto:listas.hir...@gmail.com>> wrote:
> I should have made my question and example clearer.


Hey Francisco,

You can't do this job with a plain regular expression, because of the 
variability of the text.  You'll have to use a script.

How big is the document you're operating on?

If JJ doesn't beat me to the punch (and fix his PHP script) I'll have a go with 
Perl later today.

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/30EDEA5A-1AB6-49F6-87FE-D78E5800C94B%40gmail.com.


Re: How to grep a list of hyperlink to capitalise the words

2021-04-19 Thread Christopher Stone
On 04/19/2021, at 08:13, jj mailto:goo...@mixio.com>> wrote:
> Here is a BBEdit Text Filter in PHP that capitalizes the text of hyperlinks.


Hey JJ,

Your script is failing when encountering punctuation:

Original:

1. THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT
2. PERMISSION IS GRANTED TO ANYONE TO USE THIS
...
20. REDISTRIBUTIONS OF SOURCE CODE (IN WHOLE OR
...
35. REDISTRIBUTIONS IN BINARY FORM (COMPILED
...
67. ALTERED VERSIONS: INCLUDING, BUT NOT LIMITED TO

Desired:

1. This Software Is Provided "As Is", Without
2. Permission Is Granted To Anyone To Use This
...
20. Redistributions Of Source Code (In Whole Or
...
35. Redistributions In Binary Form (Compiled
...
67. Altered Versions: Including, But Not Limited To

JJ's Script:

1. This Software Is Provided "as Is", Without
2. Permission Is Granted To Anyone To Use This
...
20. Redistributions Of Source Code (in Whole Or
...
35. Redistributions In Binary Form (compiled
...
67. Altered Versions: Including, But Not Limited To


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/629CC4D4-C4A3-4E5E-842B-79866BB25F6A%40gmail.com.


Re: Can't launch BBEdit

2021-04-16 Thread Christopher Stone
On 04/16/2021, at 02:23, @lbutlr mailto:krem...@kreme.com>> 
wrote:
> I added the BBEdit manual to my Books.app Library. Maybe I'll even remember 
> it's there the next time I am in desperate need, but I've been using BBEdit 
> for almost 20 years (yes, I'm a n00b) and this is the first time I could't 
> get into the app to open the manual, so… 


Hey Lewis,

Give it a relevant tag like ‘BBEdit.Manual’, so Spotlight can find it easily.

tag:BBEdit.Manual

And since you’re a bit of a shell-head there's always:

mdfind -onlyin ~/Library/ "(kMDItemDisplayName = '*bbedit user manual*'cdw || \
kMDItemAlternateNames = '*bbedit user manual*'cdw) && \
kMDItemContentTypeTree = 'com.adobe.pdf*'c" | sort -g

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/4398AE6F-BA45-487C-864C-9B48AB264847%40gmail.com.


Re: Applescript - move to end of document

2021-04-14 Thread Christopher Stone
On 04/14/2021, at 11:28, Rich Siegel mailto:sie...@barebones.com>> wrote:
> This should work:
> 
>   tell app "BBEdit"
>   activate
>   open file_path
>   select insertion point after last character of document 1
>   end tell
> 
> (It's best to always target documents, rather than windows; though that's not 
> the proximate issue here. "document 1" is always the active document.)


Hey Folks,

Here's another method:

tell application "BBEdit"
tell text of front document
select insertion point after it
end tell
end tell

I nearly always prefer to use tell-blocks to reference objects rather than 
one-liners, because frequently when I forget to do so I end up having to 
refactor my code when I add or change something.

For this use-case I might do something like this:

tell application "BBEdit"
tell front document
tell its text to select insertion point after it
end tell
end tell

But if I will take time to write the code “correctly”:

tell application "BBEdit"
tell front document
tell its text
select insertion point after it
end tell
end tell
end tell

Then I have no problem coming back in later and doing more with either the 
document, or the text, or both.

Probably 8 times out of 10 I'll regret not using the above construct, because a 
short time later I'll be modifying it to something on the order of this:

tell application "BBEdit"
tell front document
tell its text
set after it to linefeed & "Some more text..."
select insertion point after it
end tell
end tell
end tell

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/F3E41D7C-4B81-4927-AC38-861DCD9EC0A1%40gmail.com.


Re: How to save out all my unsaved untitled files

2021-03-29 Thread Christopher Stone
On 03/29/2021, at 10:20, Steve Weiss mailto:st...@wgacany.com>> wrote:
> What I would like to do, is take all of these unsaved, untitled documents and 
> save them all out to a folder so that I can just grep through them without 
> having to use the Find feature in BBEdit - and then close all of the 
> documents so I don't have to keep reopening all of them. 
> 
> How can I do this without having to press save on every single file 
> individually?  I've seen applescripts but they all seem to assume the files 
> have already been saved once.


Hey Steve,

"Easily" done.

I've commented-out the commands that close the documents after saving, so you 
can verify everything before closing them.  (I'm confident it works on my 
system, so I am no longer concerned about this – but on first run especially on 
a newer system I'd want to verify.)

--
Best Regards,
Chris


--------
# Auth: Christopher Stone
# dCre: 2016/10/18 03:00
# dMod: 2021/03/29 10:33
# Appl: BBEdit
# Task: Save unsaved text documents and shell documents to a date-stamped 
folder in the Finder.
# : Then close those documents and open the folder in the Finder.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Finder, @Save, @Unsaved, 
@Text_Documents, @Shell_Documents


set saveFolderWasCreated to false

tell application "BBEdit"

set unsavedDocList to text documents whose on disk is false

if length of unsavedDocList > 0 then

set saveFolderPath to makeSaveFolder() of me
set saveFolderWasCreated to true

repeat with theDoc in unsavedDocList
set docName to name of theDoc
set docName to findReplTIDS(":", ";", docName) of me
set docID to ID of theDoc
save theDoc to (saveFolderPath & docName) & ".txt"
# close document id docID
end repeat

end if

set unsavedShellDocList to every shell document whose on disk is false

if length of unsavedShellDocList > 0 then

if not saveFolderWasCreated then
set saveFolderPath to makeSaveFolder()
set saveFolderWasCreated to true
end if

repeat with theDoc in unsavedShellDocList
set docID to ID of theDoc
save theDoc to (saveFolderPath & (name of theDoc)) & ".worksheet"
# close document id docID
end repeat

end if

end tell

if saveFolderWasCreated then
tell application "Finder"
activate
open (alias saveFolderPath)
end tell
end if


--» HANDLERS

on findReplTIDS(_find, _replace, _string)
set oldTIDS to AppleScript's text item delimiters
set AppleScript's text item delimiters to _find
set _string to text items of _string
set AppleScript's text item delimiters to _replace
set _string to _string as text
set AppleScript's text item delimiters to oldTIDS
return _string
end findReplTIDS

on makeSaveFolder()
set newFolderName to do shell script "date \"+%Y-%m-%d %H.%M\""
set newFolderName to "BBEdit → Untitled Docs → Saved " & newFolderName
tell application "Finder"
set newFolder to make new folder at (path to desktop folder) with 
properties {name:newFolderName}
return newFolder as text
end tell
end makeSaveFolder


-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/0C713B1E-AAEE-4DDA-B45B-4D12B3A594BE%40gmail.com.


Re: GREP pattern to replace the first element with a tab

2021-03-21 Thread Christopher Stone
On 03/21/2021, at 03:39, samar mailto:arnet...@bluewin.ch>> wrote:
> The reason you cannot reproduce the error with your file may be that the 
> second column is limited to three different texts (B1, B2, and B3) whereas in 
> mine there are more (up to B7 here, but the script should also work with more 
> than seven):


Hey Samar,

Nyet.  The logic of JD's script is quite clear if you know how to read Perl, 
and that shouldn't happen.

My best guess is your test file is different in structure than what you've 
given us as an example, and that's throwing off JD's script – but I can't tell 
without being able to reproduce the problem.

I created a 10,000 line test file with 1000 A-groups, and JD's script works 
perfectly in about 1/4 of a second on my old Mid-2010 17" 2.66 GHz Intel Core 
i7 MacBook Pro.

When asking for text processing it's best to give real-world data if at all 
possible, because the devil is in the details – and small anomalies can cause 
big problems.

I've rewritten JD's script to hopefully reduce any chance of error.  It's a bit 
terse, but hopefully the commenting overcomes that.

Why wait 8 seconds when instantaneous is available?

--
Best Regards,
Chris


#!/usr/bin/env perl -sw
# 
---------
# Auth: Christopher Stone mailto:scriptmeis...@thestoneforge.com>>
# dCre: 2012/11/27 08:12
# dMod: 2021/03/21 21:13 
# Task: Create Indented Structure from a 2 Column tab-delimited table.
# Tags: @ccstone, @Shell, @Script, @Indented, @Column, @Table
# 
-
use v5.010;

my $column1StartStr = "";# Initialize variable

while (<>) { # Process Lines one at a time.

   m!(^[^\t]+)(\t.+)!m;  # Matches Column 1 & [\t]Column 2 in the 
current line to $1 & $2.

   if ($1 eq $column1StartStr) { # Equality test – start-state of Col A & Col A 
of current line:

  say "$2";  # If equal; print only Col B with \t delim.

   } else {

  say "$1$2";# If NOT equal; print both columns.
  $column1StartStr = $1; # If NOT equal; reset Col A start string.

   }

}

# 
-


-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" 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 bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/EF00E382-AECA-426B-99FD-A49353D18137%40gmail.com.


  1   2   3   4   5   6   7   8   9   >