Re: Need help simplifying apple script with grep

2023-03-23 Thread Mathias
Chris, worked great, you're the best. Thanks!

måndag 20 mars 2023 kl. 23:28:56 UTC+1 skrev 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/968a48f6-85fe-4a28-8146-6789ef4cc819n%40googlegroups.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-19 Thread Mathias
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.

To recap. I'm trying to write an all-encompassing script that converts 
IOS/Xcode localisation files to Android's format. This includes the strings 
as well as comment lines. 
Examples of rows:

*IOS:*
/* LOGIN */
"login_welcome" = "Welcome to My app";

*ANDROID:*

Welcome to My App

*CURRENT SCRIPT, BASED ON YOU COOL GUYS GREAT FEEDBACK:*

*tell* *application* "BBEdit"

*tell* *front* *text window*

*replace* "(\"[^\"]+?\") = \"([^\"]+?)\";" using "\\2" options ¬

{search mode:*grep*, case sensitive:*false*, starting at top:*true*} -- 
RegEx replacement.

*replace* "/\\*([^*]*?)\\*/" using "" options ¬

{search mode:*grep*, case sensitive:*false*, starting at top:*true*}

*replace* "%@" using "%1$s" options {case sensitive:*false*, starting at top
:*true*} -- Literal replacement.

*end* *tell*

*end* *tell*


OK, but I have one outstanding issue.

What I would like is take *everything* between the last to quote signs as 
the body of the xml node. However, it doesn't work with escaped characters.


As an example, if I take the above row and change it to

"login_welcome" = "Welcome to \"My App\" "; - it doesn't work. 


What I would like is basically "between quote one and two, use in , then everything between quote number three and the ending ' "; ' 
use as body, then end with .


Does this name sense?






lördag 18 mars 2023 kl. 21:24:40 UTC+1 skrev Kaveh Bazargan:

> All sounds good Mathias. I miss AppleScript. I wrote a lot of it to help 
> editing videos. It's just that grep is hard to read as it is!!
>
> Perhaps not relevant, but I recently found Text Factory in BBEdit that 
> lets you string lots of greps together...
>
> Regards
> Kaveh
>
> On Sat, 18 Mar 2023 at 11:45, Mathias  wrote:
>
>> Huge thanks Bruce. You guys are insane at grep'ing, sed'ing etc. The 
>> answers I've gotten in here are like machine code sometimes. :)
>>
>> Kaveh, the reason I use AppleScript is because I've used it outside 
>> BBEdit in the past, so I'm most familiar with that setup. I've gotten solid 
>> evidence in here previously that it's probably not the best tool for the 
>> job, but when you deal with this stuff once every three years you kind of 
>> don't have time to learn something new... (I probably should I guess). 
>> Again, thanks.
>>
>> fredag 17 mars 2023 kl. 16:18:21 UTC+1 skrev Kaveh Bazargan:
>>
>>> Thanks Bruce. I am familiar with grep and use it a lot. Also used a lot 
>>> of AppleScript in the past but no regex in that. 
>>>
>>> It's just that the extra escape and all the verbosity in AppleScript 
>>> makes it painful to decode!
>>>
>>> On Fri, 17 Mar 2023 at 14:30, Bruce Van Allen  wrote:
>>>
 Yes, double escapes are needed. As handy as Applescript is, quoting is 
 a major pain point.

 ‘*’ has special meaning within regular expressions, so it must be 
 escaped when trying to match a literal ‘*’. So that's the first ‘\’. Then 
 Applescript needs that ‘\’ escaped, so we get ‘\\*’.

 The BBEdit User Manual (PDF download via the Help menu) has a good 
 discussion of this.

 — Bruce

 _bruce__van_allen__santa_cruz_ca_





 > On Mar 17, 2023, at 7:23 AM, Kaveh Bazargan  
 wrote:
 > 
 > Quick question: For AppleScript you need to double escape, right? so:
 > • 
 > in AppleScript: \\*
 > • becomes \* in BBEdit
 > • to find "*"
 > 
 > 
 > On Fri, 17 Mar 2023 at 13:36, Bruce Van Allen  
 wrote:
 > Oops - I mis-typed one bit: the inner part of the find pattern should 
 be “[^*]” - asterisk instead of plus sign.
 > 
 > tell application “BBEdit"
 >   tell front text window
 > replace "/\\*([^*]*?)\\*/" using "" options ¬
 > {search mode:grep, case sensitive:false, starting at top:true}
 >   end tell
 > end tell
 > 
 > 
 > — Bruce
 > 
 > _bruce__van_allen__santa_cruz_ca_
 > 
 > 
 > 
 > 
 > 
 > > On Mar 17, 2023, at 6:08 AM, Bruce Van Allen  
 wrote:
 > > 
 > > Here’s a slightly amended version of your script:
 > > 
 > > tell application “BBEdit”
 > >  tell front text window
 > >replace "/\\*([^+]*?)\\*/" using "" options ¬
 > > {search mode:grep, case sensitive:false, starting at top:true}
 > >  end tell
 > > end tell
 > > 
 > > The differences are:
 > > 
 > > - no parentheses () surrounding the whole find pattern because that 
 becomes the first capture, which you use in the replacement pattern as 
 ‘\1’.
 > > 
 > > - added parens around the inner part of the find pattern, in order 
 to capture what’s between the JS comment markers.
 > > 
 > > -  if you needed to keep that outer parens capture for some other 
 reason, then change the replacement pattern to “” 

Re: Need help simplifying apple script with grep

2023-03-18 Thread Kaveh Bazargan
All sounds good Mathias. I miss AppleScript. I wrote a lot of it to help
editing videos. It's just that grep is hard to read as it is!!

Perhaps not relevant, but I recently found Text Factory in BBEdit that lets
you string lots of greps together...

Regards
Kaveh

On Sat, 18 Mar 2023 at 11:45, Mathias  wrote:

> Huge thanks Bruce. You guys are insane at grep'ing, sed'ing etc. The
> answers I've gotten in here are like machine code sometimes. :)
>
> Kaveh, the reason I use AppleScript is because I've used it outside BBEdit
> in the past, so I'm most familiar with that setup. I've gotten solid
> evidence in here previously that it's probably not the best tool for the
> job, but when you deal with this stuff once every three years you kind of
> don't have time to learn something new... (I probably should I guess).
> Again, thanks.
>
> fredag 17 mars 2023 kl. 16:18:21 UTC+1 skrev Kaveh Bazargan:
>
>> Thanks Bruce. I am familiar with grep and use it a lot. Also used a lot
>> of AppleScript in the past but no regex in that.
>>
>> It's just that the extra escape and all the verbosity in AppleScript
>> makes it painful to decode!
>>
>> On Fri, 17 Mar 2023 at 14:30, Bruce Van Allen  wrote:
>>
>>> Yes, double escapes are needed. As handy as Applescript is, quoting is a
>>> major pain point.
>>>
>>> ‘*’ has special meaning within regular expressions, so it must be
>>> escaped when trying to match a literal ‘*’. So that's the first ‘\’. Then
>>> Applescript needs that ‘\’ escaped, so we get ‘\\*’.
>>>
>>> The BBEdit User Manual (PDF download via the Help menu) has a good
>>> discussion of this.
>>>
>>> — Bruce
>>>
>>> _bruce__van_allen__santa_cruz_ca_
>>>
>>>
>>>
>>>
>>>
>>> > On Mar 17, 2023, at 7:23 AM, Kaveh Bazargan 
>>> wrote:
>>> >
>>> > Quick question: For AppleScript you need to double escape, right? so:
>>> > •
>>> > in AppleScript: \\*
>>> > • becomes \* in BBEdit
>>> > • to find "*"
>>> >
>>> >
>>> > On Fri, 17 Mar 2023 at 13:36, Bruce Van Allen  wrote:
>>> > Oops - I mis-typed one bit: the inner part of the find pattern should
>>> be “[^*]” - asterisk instead of plus sign.
>>> >
>>> > tell application “BBEdit"
>>> >   tell front text window
>>> > replace "/\\*([^*]*?)\\*/" using "" options ¬
>>> > {search mode:grep, case sensitive:false, starting at top:true}
>>> >   end tell
>>> > end tell
>>> >
>>> >
>>> > — Bruce
>>> >
>>> > _bruce__van_allen__santa_cruz_ca_
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > > On Mar 17, 2023, at 6:08 AM, Bruce Van Allen 
>>> wrote:
>>> > >
>>> > > Here’s a slightly amended version of your script:
>>> > >
>>> > > tell application “BBEdit”
>>> > >  tell front text window
>>> > >replace "/\\*([^+]*?)\\*/" using "" options ¬
>>> > > {search mode:grep, case sensitive:false, starting at top:true}
>>> > >  end tell
>>> > > end tell
>>> > >
>>> > > The differences are:
>>> > >
>>> > > - no parentheses () surrounding the whole find pattern because that
>>> becomes the first capture, which you use in the replacement pattern as ‘\1’.
>>> > >
>>> > > - added parens around the inner part of the find pattern, in order
>>> to capture what’s between the JS comment markers.
>>> > >
>>> > > -  if you needed to keep that outer parens capture for some other
>>> reason, then change the replacement pattern to “” (assuming that
>>> part stays the second parens-capture).
>>> > >
>>> > > - I omitted the replace “%@“ line to keep this part of the script
>>> clear.
>>> > >
>>> > > Using the script as I wrote it above
>>> > >
>>> > > /* some commented stuff */ /*some more*/
>>> > >
>>> > > And /* some more*/
>>> > >
>>> > > is transformed in one step into
>>> > >
>>> > >  
>>> > >
>>> > > And 
>>> > >
>>> > >
>>> > > HTH
>>> > >
>>> > >— Bruce
>>> > >
>>> > > _bruce__van_allen__santa_cruz_ca_
>>> > >
>>> > >
>>> > >
>>> > >
>>> > >
>>> > >> On Mar 17, 2023, at 3:04 AM, Mathias  wrote:
>>> > >>
>>> > >> OK, so I'm working on an apple script to replace Localizable
>>> (apple) comments on the /* ... */ format to 
>>> > >>
>>> > >> I got it working, but I'm using two commands because I couldn't
>>> figure the grep out... can this be simplified with only one "replace" ?
>>> > >>
>>> > >> pointers appreciated, script here:
>>> > >>
>>> > >> tell application "BBEdit"
>>> > >> tell front text window
>>> > >> replace "(/\\*[^\\*]*\\*/)" using "" options ¬
>>> > >> {search mode:grep, case sensitive:false, starting at top:true}
>>> > >> replace "(/\\*|\\*/)" using "" options {search mode:grep, case
>>> sensitive:false, starting at top:true}
>>> > >> replace "%@" using "%1$s" options {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 "
>>> sup...@barebones.com" rather than posting here. Follow @bbedit on
>>> Twitter: 
>>> > >> ---
>>> > >> You received this message 

Re: Need help simplifying apple script with grep

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


Thanks for the reminder! I use Script Debugger, but hadn’t been using that 
capability.

— Bruce

_bruce__van_allen__santa_cruz_ca_


-- 
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/D6F910FC-CD24-43DD-8924-FEA3F092FD1F%40cruzio.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: Need help simplifying apple script with grep

2023-03-18 Thread Mathias
Huge thanks Bruce. You guys are insane at grep'ing, sed'ing etc. The 
answers I've gotten in here are like machine code sometimes. :)

Kaveh, the reason I use AppleScript is because I've used it outside BBEdit 
in the past, so I'm most familiar with that setup. I've gotten solid 
evidence in here previously that it's probably not the best tool for the 
job, but when you deal with this stuff once every three years you kind of 
don't have time to learn something new... (I probably should I guess). 
Again, thanks.

fredag 17 mars 2023 kl. 16:18:21 UTC+1 skrev Kaveh Bazargan:

> Thanks Bruce. I am familiar with grep and use it a lot. Also used a lot 
> of AppleScript in the past but no regex in that. 
>
> It's just that the extra escape and all the verbosity in AppleScript makes 
> it painful to decode!
>
> On Fri, 17 Mar 2023 at 14:30, Bruce Van Allen  wrote:
>
>> Yes, double escapes are needed. As handy as Applescript is, quoting is a 
>> major pain point.
>>
>> ‘*’ has special meaning within regular expressions, so it must be escaped 
>> when trying to match a literal ‘*’. So that's the first ‘\’. Then 
>> Applescript needs that ‘\’ escaped, so we get ‘\\*’.
>>
>> The BBEdit User Manual (PDF download via the Help menu) has a good 
>> discussion of this.
>>
>> — Bruce
>>
>> _bruce__van_allen__santa_cruz_ca_
>>
>>
>>
>>
>>
>> > On Mar 17, 2023, at 7:23 AM, Kaveh Bazargan  
>> wrote:
>> > 
>> > Quick question: For AppleScript you need to double escape, right? so:
>> > • 
>> > in AppleScript: \\*
>> > • becomes \* in BBEdit
>> > • to find "*"
>> > 
>> > 
>> > On Fri, 17 Mar 2023 at 13:36, Bruce Van Allen  wrote:
>> > Oops - I mis-typed one bit: the inner part of the find pattern should 
>> be “[^*]” - asterisk instead of plus sign.
>> > 
>> > tell application “BBEdit"
>> >   tell front text window
>> > replace "/\\*([^*]*?)\\*/" using "" options ¬
>> > {search mode:grep, case sensitive:false, starting at top:true}
>> >   end tell
>> > end tell
>> > 
>> > 
>> > — Bruce
>> > 
>> > _bruce__van_allen__santa_cruz_ca_
>> > 
>> > 
>> > 
>> > 
>> > 
>> > > On Mar 17, 2023, at 6:08 AM, Bruce Van Allen  wrote:
>> > > 
>> > > Here’s a slightly amended version of your script:
>> > > 
>> > > tell application “BBEdit”
>> > >  tell front text window
>> > >replace "/\\*([^+]*?)\\*/" using "" options ¬
>> > > {search mode:grep, case sensitive:false, starting at top:true}
>> > >  end tell
>> > > end tell
>> > > 
>> > > The differences are:
>> > > 
>> > > - no parentheses () surrounding the whole find pattern because that 
>> becomes the first capture, which you use in the replacement pattern as ‘\1’.
>> > > 
>> > > - added parens around the inner part of the find pattern, in order to 
>> capture what’s between the JS comment markers.
>> > > 
>> > > -  if you needed to keep that outer parens capture for some other 
>> reason, then change the replacement pattern to “” (assuming that 
>> part stays the second parens-capture).
>> > > 
>> > > - I omitted the replace “%@“ line to keep this part of the script 
>> clear.
>> > > 
>> > > Using the script as I wrote it above
>> > > 
>> > > /* some commented stuff */ /*some more*/
>> > > 
>> > > And /* some more*/
>> > > 
>> > > is transformed in one step into 
>> > > 
>> > >  
>> > > 
>> > > And 
>> > > 
>> > > 
>> > > HTH
>> > > 
>> > >— Bruce
>> > > 
>> > > _bruce__van_allen__santa_cruz_ca_
>> > > 
>> > > 
>> > > 
>> > > 
>> > > 
>> > >> On Mar 17, 2023, at 3:04 AM, Mathias  wrote:
>> > >> 
>> > >> OK, so I'm working on an apple script to replace Localizable (apple) 
>> comments on the /* ... */ format to 
>> > >> 
>> > >> I got it working, but I'm using two commands because I couldn't 
>> figure the grep out... can this be simplified with only one "replace" ? 
>> > >> 
>> > >> pointers appreciated, script here:
>> > >> 
>> > >> tell application "BBEdit"
>> > >> tell front text window
>> > >> replace "(/\\*[^\\*]*\\*/)" using "" options ¬
>> > >> {search mode:grep, case sensitive:false, starting at top:true} 
>> > >> replace "(/\\*|\\*/)" using "" options {search mode:grep, case 
>> sensitive:false, starting at top:true} 
>> > >> replace "%@" using "%1$s" options {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 "
>> sup...@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+un...@googlegroups.com.
>> > >> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/bbedit/65afd9cc-0a86-4821-b302-20b2948c3cdcn%40googlegroups.com
>> .
>> > > 
>> > > -- 
>> > > This is the BBEdit 

Re: Need help simplifying apple script with grep

2023-03-17 Thread Kaveh Bazargan
Thanks Bruce. I am familiar with grep and use it a lot. Also used a lot
of AppleScript in the past but no regex in that.

It's just that the extra escape and all the verbosity in AppleScript makes
it painful to decode!

On Fri, 17 Mar 2023 at 14:30, Bruce Van Allen  wrote:

> Yes, double escapes are needed. As handy as Applescript is, quoting is a
> major pain point.
>
> ‘*’ has special meaning within regular expressions, so it must be escaped
> when trying to match a literal ‘*’. So that's the first ‘\’. Then
> Applescript needs that ‘\’ escaped, so we get ‘\\*’.
>
> The BBEdit User Manual (PDF download via the Help menu) has a good
> discussion of this.
>
> — Bruce
>
> _bruce__van_allen__santa_cruz_ca_
>
>
>
>
>
> > On Mar 17, 2023, at 7:23 AM, Kaveh Bazargan 
> wrote:
> >
> > Quick question: For AppleScript you need to double escape, right? so:
> > •
> > in AppleScript: \\*
> > • becomes \* in BBEdit
> > • to find "*"
> >
> >
> > On Fri, 17 Mar 2023 at 13:36, Bruce Van Allen  wrote:
> > Oops - I mis-typed one bit: the inner part of the find pattern should be
> “[^*]” - asterisk instead of plus sign.
> >
> > tell application “BBEdit"
> >   tell front text window
> > replace "/\\*([^*]*?)\\*/" using "" options ¬
> > {search mode:grep, case sensitive:false, starting at top:true}
> >   end tell
> > end tell
> >
> >
> > — Bruce
> >
> > _bruce__van_allen__santa_cruz_ca_
> >
> >
> >
> >
> >
> > > On Mar 17, 2023, at 6:08 AM, Bruce Van Allen  wrote:
> > >
> > > Here’s a slightly amended version of your script:
> > >
> > > tell application “BBEdit”
> > >  tell front text window
> > >replace "/\\*([^+]*?)\\*/" using "" options ¬
> > > {search mode:grep, case sensitive:false, starting at top:true}
> > >  end tell
> > > end tell
> > >
> > > The differences are:
> > >
> > > - no parentheses () surrounding the whole find pattern because that
> becomes the first capture, which you use in the replacement pattern as ‘\1’.
> > >
> > > - added parens around the inner part of the find pattern, in order to
> capture what’s between the JS comment markers.
> > >
> > > -  if you needed to keep that outer parens capture for some other
> reason, then change the replacement pattern to “” (assuming that
> part stays the second parens-capture).
> > >
> > > - I omitted the replace “%@“ line to keep this part of the script
> clear.
> > >
> > > Using the script as I wrote it above
> > >
> > > /* some commented stuff */ /*some more*/
> > >
> > > And /* some more*/
> > >
> > > is transformed in one step into
> > >
> > >  
> > >
> > > And 
> > >
> > >
> > > HTH
> > >
> > >— Bruce
> > >
> > > _bruce__van_allen__santa_cruz_ca_
> > >
> > >
> > >
> > >
> > >
> > >> On Mar 17, 2023, at 3:04 AM, Mathias  wrote:
> > >>
> > >> OK, so I'm working on an apple script to replace Localizable (apple)
> comments on the /* ... */ format to 
> > >>
> > >> I got it working, but I'm using two commands because I couldn't
> figure the grep out... can this be simplified with only one "replace" ?
> > >>
> > >> pointers appreciated, script here:
> > >>
> > >> tell application "BBEdit"
> > >> tell front text window
> > >> replace "(/\\*[^\\*]*\\*/)" using "" options ¬
> > >> {search mode:grep, case sensitive:false, starting at top:true}
> > >> replace "(/\\*|\\*/)" using "" options {search mode:grep, case
> sensitive:false, starting at top:true}
> > >> replace "%@" using "%1$s" options {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: 
> > >> ---
> > >> 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/65afd9cc-0a86-4821-b302-20b2948c3cdcn%40googlegroups.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/B37085B8-A95C-4105-B396-5E089AADFEFB%40cruzio.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 

Re: Need help simplifying apple script with grep

2023-03-17 Thread Bruce Van Allen
Yes, double escapes are needed. As handy as Applescript is, quoting is a major 
pain point.

‘*’ has special meaning within regular expressions, so it must be escaped when 
trying to match a literal ‘*’. So that's the first ‘\’. Then Applescript needs 
that ‘\’ escaped, so we get ‘\\*’.
 
The BBEdit User Manual (PDF download via the Help menu) has a good discussion 
of this.

— Bruce

_bruce__van_allen__santa_cruz_ca_





> On Mar 17, 2023, at 7:23 AM, Kaveh Bazargan  wrote:
> 
> Quick question: For AppleScript you need to double escape, right? so:
> • 
> in AppleScript: \\*
> • becomes \* in BBEdit
> • to find "*"
> 
> 
> On Fri, 17 Mar 2023 at 13:36, Bruce Van Allen  wrote:
> Oops - I mis-typed one bit: the inner part of the find pattern should be 
> “[^*]” - asterisk instead of plus sign.
> 
> tell application “BBEdit"
>   tell front text window
> replace "/\\*([^*]*?)\\*/" using "" options ¬
> {search mode:grep, case sensitive:false, starting at top:true}
>   end tell
> end tell
> 
> 
> — Bruce
> 
> _bruce__van_allen__santa_cruz_ca_
> 
> 
> 
> 
> 
> > On Mar 17, 2023, at 6:08 AM, Bruce Van Allen  wrote:
> > 
> > Here’s a slightly amended version of your script:
> > 
> > tell application “BBEdit”
> >  tell front text window
> >replace "/\\*([^+]*?)\\*/" using "" options ¬
> > {search mode:grep, case sensitive:false, starting at top:true}
> >  end tell
> > end tell
> > 
> > The differences are:
> > 
> > - no parentheses () surrounding the whole find pattern because that becomes 
> > the first capture, which you use in the replacement pattern as ‘\1’.
> > 
> > - added parens around the inner part of the find pattern, in order to 
> > capture what’s between the JS comment markers.
> > 
> > -  if you needed to keep that outer parens capture for some other reason, 
> > then change the replacement pattern to “” (assuming that part stays 
> > the second parens-capture).
> > 
> > - I omitted the replace “%@“ line to keep this part of the script clear.
> > 
> > Using the script as I wrote it above
> > 
> > /* some commented stuff */ /*some more*/
> > 
> > And /* some more*/
> > 
> > is transformed in one step into 
> > 
> >  
> > 
> > And 
> > 
> > 
> > HTH
> > 
> >— Bruce
> > 
> > _bruce__van_allen__santa_cruz_ca_
> > 
> > 
> > 
> > 
> > 
> >> On Mar 17, 2023, at 3:04 AM, Mathias  wrote:
> >> 
> >> OK, so I'm working on an apple script to replace Localizable (apple) 
> >> comments on the /* ... */ format to 
> >> 
> >> I got it working, but I'm using two commands because I couldn't figure the 
> >> grep out... can this be simplified with only one "replace" ? 
> >> 
> >> pointers appreciated, script here:
> >> 
> >> tell application "BBEdit"
> >> tell front text window
> >> replace "(/\\*[^\\*]*\\*/)" using "" options ¬
> >> {search mode:grep, case sensitive:false, starting at top:true} 
> >> replace "(/\\*|\\*/)" using "" options {search mode:grep, case 
> >> sensitive:false, starting at top:true} 
> >> replace "%@" using "%1$s" options {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: 
> >> 
> >> --- 
> >> 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/65afd9cc-0a86-4821-b302-20b2948c3cdcn%40googlegroups.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/B37085B8-A95C-4105-B396-5E089AADFEFB%40cruzio.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 
> 

Re: Need help simplifying apple script with grep

2023-03-17 Thread Kaveh Bazargan
Quick question: For AppleScript you need to double escape, right? so:

   - in AppleScript: \\*
   - becomes \* in BBEdit
   - to find "*"


On Fri, 17 Mar 2023 at 13:36, Bruce Van Allen  wrote:

> Oops - I mis-typed one bit: the inner part of the find pattern should be
> “[^*]” - asterisk instead of plus sign.
>
> tell application “BBEdit"
>   tell front text window
> replace "/\\*([^*]*?)\\*/" using "" options ¬
> {search mode:grep, case sensitive:false, starting at top:true}
>   end tell
> end tell
>
>
> — Bruce
>
> _bruce__van_allen__santa_cruz_ca_
>
>
>
>
>
> > On Mar 17, 2023, at 6:08 AM, Bruce Van Allen  wrote:
> >
> > Here’s a slightly amended version of your script:
> >
> > tell application “BBEdit”
> >  tell front text window
> >replace "/\\*([^+]*?)\\*/" using "" options ¬
> > {search mode:grep, case sensitive:false, starting at top:true}
> >  end tell
> > end tell
> >
> > The differences are:
> >
> > - no parentheses () surrounding the whole find pattern because that
> becomes the first capture, which you use in the replacement pattern as ‘\1’.
> >
> > - added parens around the inner part of the find pattern, in order to
> capture what’s between the JS comment markers.
> >
> > -  if you needed to keep that outer parens capture for some other
> reason, then change the replacement pattern to “” (assuming that
> part stays the second parens-capture).
> >
> > - I omitted the replace “%@“ line to keep this part of the script clear.
> >
> > Using the script as I wrote it above
> >
> > /* some commented stuff */ /*some more*/
> >
> > And /* some more*/
> >
> > is transformed in one step into
> >
> >  
> >
> > And 
> >
> >
> > HTH
> >
> >— Bruce
> >
> > _bruce__van_allen__santa_cruz_ca_
> >
> >
> >
> >
> >
> >> On Mar 17, 2023, at 3:04 AM, Mathias  wrote:
> >>
> >> OK, so I'm working on an apple script to replace Localizable (apple)
> comments on the /* ... */ format to 
> >>
> >> I got it working, but I'm using two commands because I couldn't figure
> the grep out... can this be simplified with only one "replace" ?
> >>
> >> pointers appreciated, script here:
> >>
> >> tell application "BBEdit"
> >> tell front text window
> >> replace "(/\\*[^\\*]*\\*/)" using "" options ¬
> >> {search mode:grep, case sensitive:false, starting at top:true}
> >> replace "(/\\*|\\*/)" using "" options {search mode:grep, case
> sensitive:false, starting at top:true}
> >> replace "%@" using "%1$s" options {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/65afd9cc-0a86-4821-b302-20b2948c3cdcn%40googlegroups.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/B37085B8-A95C-4105-B396-5E089AADFEFB%40cruzio.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/B4B02A99-8F77-4877-93AD-328302B74BBB%40cruzio.com
> .
>


-- 
Kaveh Bazargan PhD
Director
River Valley Technologies  ● Twitter
 ● LinkedIn
 ● ORCID
 ● @kaveh1000@mastodon.social

*Accelerating the Communication of Research*

*


Re: Need help simplifying apple script with grep

2023-03-17 Thread Bruce Van Allen
Oops - I mis-typed one bit: the inner part of the find pattern should be “[^*]” 
- asterisk instead of plus sign.

tell application “BBEdit"
  tell front text window
replace "/\\*([^*]*?)\\*/" using "" options ¬
{search mode:grep, case sensitive:false, starting at top:true}
  end tell
end tell


— Bruce

_bruce__van_allen__santa_cruz_ca_





> On Mar 17, 2023, at 6:08 AM, Bruce Van Allen  wrote:
> 
> Here’s a slightly amended version of your script:
> 
> tell application “BBEdit”
>  tell front text window
>replace "/\\*([^+]*?)\\*/" using "" options ¬
> {search mode:grep, case sensitive:false, starting at top:true}
>  end tell
> end tell
> 
> The differences are:
> 
> - no parentheses () surrounding the whole find pattern because that becomes 
> the first capture, which you use in the replacement pattern as ‘\1’.
> 
> - added parens around the inner part of the find pattern, in order to capture 
> what’s between the JS comment markers.
> 
> -  if you needed to keep that outer parens capture for some other reason, 
> then change the replacement pattern to “” (assuming that part stays 
> the second parens-capture).
> 
> - I omitted the replace “%@“ line to keep this part of the script clear.
> 
> Using the script as I wrote it above
> 
> /* some commented stuff */ /*some more*/
> 
> And /* some more*/
> 
> is transformed in one step into 
> 
>  
> 
> And 
> 
> 
> HTH
> 
>— Bruce
> 
> _bruce__van_allen__santa_cruz_ca_
> 
> 
> 
> 
> 
>> On Mar 17, 2023, at 3:04 AM, Mathias  wrote:
>> 
>> OK, so I'm working on an apple script to replace Localizable (apple) 
>> comments on the /* ... */ format to 
>> 
>> I got it working, but I'm using two commands because I couldn't figure the 
>> grep out... can this be simplified with only one "replace" ? 
>> 
>> pointers appreciated, script here:
>> 
>> tell application "BBEdit"
>> tell front text window
>> replace "(/\\*[^\\*]*\\*/)" using "" options ¬
>> {search mode:grep, case sensitive:false, starting at top:true} 
>> replace "(/\\*|\\*/)" using "" options {search mode:grep, case 
>> sensitive:false, starting at top:true} 
>> replace "%@" using "%1$s" options {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: 
>> 
>> --- 
>> 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/65afd9cc-0a86-4821-b302-20b2948c3cdcn%40googlegroups.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/B37085B8-A95C-4105-B396-5E089AADFEFB%40cruzio.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/B4B02A99-8F77-4877-93AD-328302B74BBB%40cruzio.com.


Re: Need help simplifying apple script with grep

2023-03-17 Thread Bruce Van Allen
Here’s a slightly amended version of your script:

tell application “BBEdit”
  tell front text window
replace "/\\*([^+]*?)\\*/" using "" options ¬
{search mode:grep, case sensitive:false, starting at top:true}
  end tell
end tell

The differences are:

- no parentheses () surrounding the whole find pattern because that becomes the 
first capture, which you use in the replacement pattern as ‘\1’.

- added parens around the inner part of the find pattern, in order to capture 
what’s between the JS comment markers.

-  if you needed to keep that outer parens capture for some other reason, then 
change the replacement pattern to “” (assuming that part stays the 
second parens-capture).

- I omitted the replace “%@“ line to keep this part of the script clear.

Using the script as I wrote it above

/* some commented stuff */ /*some more*/

And /* some more*/

is transformed in one step into 

 

And 


HTH

— Bruce

_bruce__van_allen__santa_cruz_ca_





> On Mar 17, 2023, at 3:04 AM, Mathias  wrote:
> 
> OK, so I'm working on an apple script to replace Localizable (apple) comments 
> on the /* ... */ format to 
> 
> I got it working, but I'm using two commands because I couldn't figure the 
> grep out... can this be simplified with only one "replace" ? 
> 
> pointers appreciated, script here:
> 
> tell application "BBEdit"
> tell front text window
> replace "(/\\*[^\\*]*\\*/)" using "" options ¬
> {search mode:grep, case sensitive:false, starting at top:true} 
> replace "(/\\*|\\*/)" using "" options {search mode:grep, case 
> sensitive:false, starting at top:true} 
> replace "%@" using "%1$s" options {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: 
> 
> --- 
> 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/65afd9cc-0a86-4821-b302-20b2948c3cdcn%40googlegroups.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/B37085B8-A95C-4105-B396-5E089AADFEFB%40cruzio.com.


Need help simplifying apple script with grep

2023-03-17 Thread Mathias
OK, so I'm working on an apple script to replace Localizable (apple) 
comments on the /* ... */ format to 

I got it working, but I'm using two commands because I couldn't figure the 
grep out... can this be simplified with only one "replace" ? 

pointers appreciated, script here:

*tell* *application* "BBEdit"

*tell* *front* *text window*

*replace* "(/\\*[^\\*]*\\*/)" using "" options ¬

{search mode:*grep*, case sensitive:*false*, starting at top:*true*} 

*replace* "(/\\*|\\*/)" using "" options {search mode:*grep*, case sensitive
:*false*, starting at top:*true*} 

*replace* "%@" using "%1$s" options {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: 
--- 
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/65afd9cc-0a86-4821-b302-20b2948c3cdcn%40googlegroups.com.