Incredible Missing Variables?

Hello, I've been using a useful script that takes some text (a URL from the current tab in Chrome), then looks for the line in a flat text file, placing the result in a variable called Local_MatchedLine if it finds it. This allows me to save the results of bit.ly links, so I don't remake them if they've already been made once, as I only get 500 custom bit.ly links per month.

So, my script has been borking a little, and I'm doing some experimenting with it. Right off the bat...the variable Local_MatchedLine (and several others that also begin with Local_) doesn't exist. I can't see it in the list of variables, and trying to manipulate the variable, like making an Applescript to getvariable the contents, returns nothing.

An yet, I know the result exists immediately after I run the script as I can speak the contents of %Variable%Local_MatchedLine% to test it and it works. The value, and the variable itself (a bunch of variables) seem to be getting "destroyed" from KM.

Has anything like this happened? Is there any situation where a variable that should exist wouldn't show in the Variables list in Preferences?

This is, as they say, a feature, not a bug :slightly_smiling_face:
Any variable prefixed with Local or Instance is created and erased every time the macro it belongs to runs, which is a good way to ensure the variable data is "fresh" each time, but bad if you want the data to persist after the macro has finished running. I'm not sure what your original reason for using local variables was, but you can just delete the Local part and run the macro again, and the variables involved should show up in the Variables pref just fine.

Wow, how silly of me to fall into that! I'll tweak my scripts and see if they magically work.

Yes, removing Local_ made it all magically work, thanks!

One additional question if I might. I need to search my flatfile for the "MatchedLine" text, and capture the entire line if it's there. Unfortunately I've got a problem. Basically I'm searching for

https://website.com/figures

but an entry

https://website.com/figures/actionfigures/

is being found in the search. What I need to do is search for https://website.com/figures[space], with a hard space after it, but I can't figure out how to make this work in the grep language.

Any advice?

No problem. What happens if you replace the .*$ with a space character in the regex you have now?

That worked perfectly! Thank you very much!

1 Like