I've been capturing a series of variables by searching a tab-delimited text file with RegEx. It works, but takes several seconds. After learning how to convert the file to JSON I came up with this, thanks to several posts on the forum. It captures the variables almost instantly. My question is, is there a more efficient way to build the macro? It seems creating a separate "Save Variable" action for each variable in a dictionary is a little tedious and since the variable names match the labels in the JSON I feel there may be a more direct method.
The sample JSON is only a small subsection of the actual JSON which contains over 100 dictionaries.
Just by reading your post, I think you can do this:
set a variable into text: get all JSON data you want to retrieve and connect these data with a unique string.
E.g., Set Local__myVar to:
Search that variable with RegEx and save them into the variables. See the example here given by @JMichaelTX :
That surprises me. I have used this method in a number of my macros and it has always been fast. Of course, it depends on the quantity of your data, and complexity of required RegEx patterns. If you want to post a real-world example of your source data, data extraction rules, and desired result, I'll take a look. If you have a lot of data, please zip the file and post that.
It looks like you are creating hundreds of KM Variables. I wonder how you plan to use all of these variables?
Hope this helps.
Thanks for the responses. The RegEx solution has worked very well since @JMichaelTX shared it with me. But in this early test I found what takes RegEx 5 sec. is done in less than 1 sec. using my current JSON method.
I'm very open to learning JXA. I just have not found sufficient resources for learning it. Most of my scripting knowledge has come through the Adobe Forum and JXA does not seem to have much of a following there.
For instance, this code gets the text in the SystemClipboard and save it to myVar:
Thank you @martin. I'll use your examples to study more on JXA.
You just have to learn to ignore people with extreme views. The user, "foo", in the Answer is well known for being highly critical of JXA. Just ignore him. JXA, like any language, is not perfect, but it works very well for the most part.
JXA is just not well known or received in the Adobe Forum:
If I understood how to use JXA along with my existing JSX Functions Library it may be worth more study. Just not getting anywhere. Perhaps there are some Adobe users in this forum who have some success stories.
You only need JXA when you want to access other apps or the macOS.