Friday, November 22, 2019

#1 2019-07-18 06:50:18 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6041

[ANN]: Script library for regular expressions, text manipulation

RegexAndStuffLib is a script library providing some basic string manipulation commands. There are commands for changing case, splitting and joining strings, various encoding and decoding commands, a range of regular expression commands, and more. It has a dictionary of terminology, to make it simple to use. You can download the library and documentation here:

https://www.macosxautomation.com/apples … ndStuffLib

A few of the commands should be useful for people who have relied on Satimage.osax.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#2 2019-07-19 02:25:37 am

ldicroce
Member
Registered: 2017-11-25
Posts: 137

Re: [ANN]: Script library for regular expressions, text manipulation

Thanks a lot, Shane!!!

Offline

 

#3 2019-07-21 11:33:09 pm

TMA
Member
Registered: 2005-11-24
Posts: 67

Re: [ANN]: Script library for regular expressions, text manipulation

Great, many thanks!

Offline

 

#4 2019-07-21 11:56:14 pm

CK
Member
From:: UK
Registered: 2018-11-04
Posts: 101

Re: [ANN]: Script library for regular expressions, text manipulation

I hope to see more libraries following this naming trend.

  - MathsPlusOtherBitsLib
  - StringsAndRantsLib
  - ListsNShitLib

Offline

 

#5 2019-07-22 04:57:33 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5106

Re: [ANN]: Script library for regular expressions, text manipulation

Shane Stanley wrote:

A few of the commands should be useful for people who have relied on Satimage.osax.


One difficulty with this claim is that the library uses different keywords and parameters from Satimage, so anyone who's relied on Satimage in the past will have to learn new stuff. This being so, they might just as well learn the relatively simple underlying AS and ASObjC commands, which have been available to scripters for some time now. It would both empower them and reduce the incidence of non-standard and occasionally non-sensical terminology in scripts, which would in turn make the scripts easier for others to understand and increase the chances of people who need help with scripts actually receiving it on the fora.


NG

Offline

 

#6 2019-07-22 06:52:05 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6041

Re: [ANN]: Script library for regular expressions, text manipulation

Nigel Garvey wrote:
Shane Stanley wrote:

A few of the commands should be useful for people who have relied on Satimage.osax.


One difficulty with this claim is that the library uses different keywords and parameters from Satimage, so anyone who's relied on Satimage in the past will have to learn new stuff.



I think that's a straw-man argument. A lot of people have used Satimage.osax primarily for regular expressions and stuff like case conversion, and the library simply provides some of those functions. I made no claim of similarity in implementation.

This being so, they might just as well learn the relatively simple underlying AS and ASObjC commands, which have been available to scripters for some time now.



I wrote a lot of it initially for myself -- I think I understand the underlying commands reasonably well, but I still appreciate convenience. And especially in terms of editing older code, there's a lot to be said for keeping ASObjC code separate.

That said, the code is all there for people to read, use and adapt, and similar code for much of it has been posted here many times already, often by me, for those who want to learn it. I suspect you overestimate people's enthusiasm for learning stuff like ASObjC (something I've obviously been guilty of too).

It would both empower them and reduce the incidence of non-standard and occasionally non-sensical terminology in scripts



If you have suggestions for improving the terminology, I'd welcome them. But I'm struggling to understand what "non-standard" means in this context. I mean, unless I've missed something, |⌘| is a little off the beaten track wink

which would in turn make the scripts easier for others to understand and increase the chances of people who need help with scripts actually receiving it on the fora.



I've read that several times, and each time I think I know what you mean, I suspect I've misunderstood. A script that uses commands and parameters documented in a standard scripting dictionary is harder for a scripter to understand than blocks of essentially Objective-C code re-written in verbose AppleScript?


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#7 2019-07-24 06:48:00 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6041

Re: [ANN]: Script library for regular expressions, text manipulation

FYI, Version 1.0.2 is now available.

This version introduces performance improvements. In particular, the regex search command is faster — significantly so if you specify a replace template, or capture groups is either unused or a single integer.

Available same place, same name.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#8 2019-07-25 01:32:43 am

akim
Member
Registered: 2010-04-04
Posts: 104

Re: [ANN]: Script library for regular expressions, text manipulation

Shane, I have found your RegexAndStuffLib to be very helpful and instructive. However, my attempt to convert a list of strings to upper case erred.

Applescript:

use scripting additions
use script "RegexAndStuffLib" version "1.0.2"
set capsText to uppercase from {"one", "two", "three"} --> "The variable theString is not defined."

In your RegexAndStuffLib.scptd, v 1.0.2, modified July 24, 2019 at 5:40 PM, as listed in  Finder's Get Info, on line 54, I noted

 return (theString's valueForKey:"localizedUppercaseString") as text

I, however, could not find a prior definition of the theString variable. Could that be the reason for the "uppercase from" command to err?
I noted similar parallels to this line of code utilizing theString in other parts of your RegexAndStuffLib.scptd.

Of no scripting importance, but while I was reading your script, I noted that the Description heading remained as RegexAndStuffLib v1.0.1 rather than v.1.0.2.This was of no scripting concern, but might be of interest in keeping readers from confusing versions.

In any regard, thank you for instructing all of us to be better Applescript coders.

Offline

 

#9 2019-07-25 01:44:07 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6041

Re: [ANN]: Script library for regular expressions, text manipulation

akim wrote:

my attempt to convert a list of strings to upper case erred.



Yes, the list-handling code is borked because of last-minute changes. Version 1.0.3 is now available, with the problem fixed. Let me know if you find any other issues. Thanks.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#10 2019-08-05 06:24:06 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6041

Re: [ANN]: Script library for regular expressions, text manipulation

FYI, Version 1.0.4 is now available. Itfixes a bug in the regex search once command, where it returns an array rather than a list when multiple capture groups are specified.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#11 2019-09-09 05:06:28 am

TMA
Member
Registered: 2005-11-24
Posts: 67

Re: [ANN]: Script library for regular expressions, text manipulation

Hi Shane,
just a small hint. The default for match case in all regex functions is false instead of true written in the dictionary.

Thanks for your great collection.

Offline

 

#12 2019-09-09 06:50:53 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6041

Re: [ANN]: Script library for regular expressions, text manipulation

Indeed it is -- thanks for the correction!


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#13 2019-09-10 12:02:36 am

TMA
Member
Registered: 2005-11-24
Posts: 67

Re: [ANN]: Script library for regular expressions, text manipulation

Hi Shane,
it would be nice if the regex commands can handle also list's instead of text only. Like the satimage find text or change commands.

Maenwhile i use my custom Handler:

Applescript:


use AppleScript version "2.4" -- macOS 10.10 or later
use framework "Foundation"
use scripting additions
use script "RegexAndStuffLib" version "1.0.4" -- /Library/Script Libraries/RegexAndStuffLib.scptd

--return my changeRegexp("1234.tif", "^(..).*", "$1")
--return my changeRegexp({"1234.tif", "abcd.tif"}, "^(..).*", "$1")

on changeRegexp(theObject, ExpressionString, ReplaceExpressionString)
   set objectClass to class of theObject
   if objectClass is list then
       local resultList
       
       set resultList to {}
       repeat with anItem in theObject
           set end of resultList to my changeRegexp(contents of anItem, ExpressionString, ReplaceExpressionString)
       end repeat
       return resultList
   else if objectClass is string or objectClass is text then
       return regex change theObject search pattern ExpressionString replace template ReplaceExpressionString
   else
       return theObject
   end if
end changeRegexp

Maybe you'd like to put something like that in.

Offline

 

#14 2019-09-10 12:31:33 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6041

Re: [ANN]: Script library for regular expressions, text manipulation

I'll consider it, but I'm not sure I can bring any value to it that you can't really do with a simple loop.

I guess I'm just a bit baffled as to why some people prefer to bury explanatory terminology in semi-opaque handlers rather than use the commands directly when needed. I mean, I know it can be a little less typing, and if you use the same stuff all the time you have familiarity on your side. But the curious thing is that in my experience people don't tend to use libraries unless they include terminology -- and then many quickly bury it.

Anyway, v1.0.5 is available with the dictionary fixed.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#15 2019-09-10 12:56:31 am

TMA
Member
Registered: 2005-11-24
Posts: 67

Re: [ANN]: Script library for regular expressions, text manipulation

Was also only a consideration, since I know that many people work or have worked with the Satimage.
Personally, I can live with your library as it is.
Everything else I build myself.

I'm very new to AppleScriptObjC, but I haven't finished reading your book 'Everday AppleScriptOpjC' yet, I'm still at it.

Many thanks for the new version 1.0.5

Offline

 

#16 2019-10-31 08:05:33 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6041

Re: [ANN]: Script library for regular expressions, text manipulation

TMA wrote:


it would be nice if the regex commands can handle also list's instead of text only.



This is now available in version 1.0.6. Get it here:

https://www.macosxautomation.com/apples … _Libs.html


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#17 2019-11-04 12:31:40 am

TMA
Member
Registered: 2005-11-24
Posts: 67

Re: [ANN]: Script library for regular expressions, text manipulation

Sounds nice. Thank you.

Offline

 

#18 2019-11-05 01:32:33 pm

nigelheinsius
Member
Registered: 2011-03-27
Posts: 8

Re: [ANN]: Script library for regular expressions, text manipulation

Shane, your script libraries are awesome. I am using the RegexAndStuffLib and FileManagerLib on a regular basis.

I notice you are updating them on a regular basis. Would it be possible to have an "Updated: [date]" on each of the libraries listed on the libraries page here?:

https://www.macosxautomation.com/apples … _Libs.html

That would help me keep up with all the great changes.

Offline

 

#19 2019-11-05 06:04:07 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6041

Re: [ANN]: Script library for regular expressions, text manipulation

Good idea -- I'll try to remember it next update.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)