Help with grepping a kmactions plist file

I want to be able to search the plist of a selected action or actions (or perhaps a selected macro), finding any variables that start with “zz”. I almost got it working, but I ran into some snags.

BTW, I don’t need to find matches in AppleScript or Javascript (but it’s probably OK if I do find them), because if they reference one of these “zz” variables, I will already have found them in the other actions (in theory). But let’s ignore that for now.

So I figure I could search for “zz” preceded by “>” or “%” (or possibly a space, but I don’t think so), and followed by “<”, “%”, or “.” (the latter for things like “position.x”). In other words, a regex like this:

(?<=[>%])(zz.*)(?=[%<.])

Assuming I could get it to only return matching strings, I could run it through sort and uniq so I had a sorted unique list of variables that start with “zz”.

So, I tried exporting the selected action(s) to a file, and doing a shell script:

grep -O ‘(?<=[>%])(zz.*)(?=[%<.])’ [file name]

But apparently OS/X grep doesn’t support lookaheads/lookbehinds.

I also tried BBFind (BBEdit command-line tool), and it works (I think) except it won’t return just the matches.

I want to use this to be able to automatically build a list of variables that should be cleaned up at the end of a macro, and I figured I’d identify those variables by preceding them with “zz”, which I already do anyway, to identify variables that don’t need to persist from macro run to macro run.

Anyone got any ideas? It’s frustrating because I’m close.

Think I got it, using perl - which I know nothing about, but apparently have because I installed the OS/X developer tools, even though I haven’t used them yet… :stuck_out_tongue:

Also, I had the regex wrong. Here’s what I’ve got:

perl -nle ‘print $& if m{(?<=[>%])zz[^%<.]*}’ /tmp/kmaction.kmactions | sort | uniq

Improvements accepted!

Just a thought about naming conventions.
You could use "DEL__SomeName".

This uses two underscores, so the "DEL__" will NOT appear in prompts.
And, should be a unique ID for variables to be deleted.

Just to be sure, you do know that KM Search action can use RegEx, right?
Also, I have found regex101.com to be great for developing and testing RegEx.

I figured people could be free to use whatever prefix they wanted, as long as it could uniquely identify a variable. Asking developers to agree on something like this is definitely in the “herding cats” category!

I originally did do something like that - always using the double-underscore, but then I changed to only using the double-underscore hen I needed to. Less typing.

Could be, but I've found most non-programmer users don't want to think about what would be unique. Providing a default is one way to go.

Awesome - thanks! Bookmarked.

Yes, I do know. But I couldn't think of a way to do what I wanted, and have it run quickly. If you can, let me know!

I am. "zz". gd&r

I would probably do it all in JXA, which has the excellent JavaScript RegEx engine.

"zz" is often used simply to sort items at the bottom of a list.
Sorry, but I think that's a bad choice for ID variables for deletion.

It also looks funny on prompt actions.

I’m not asking you to use “zz”, you know. Use whatever you want. Be free! Be happy!