ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE. Software > Find And Run Robot

Use of Variables inside Aliases

(1/2) > >>

Hello there, new user here!

I've gotta say that I am having an absolute blast fiddling around with Find And Run Robot. I adore how amazingly powerful it can be with a footprint of 3MBytes. I'm also digging big time that it's not "indexed", minimizing the footprint even further. I'm most definitely gonna start using it as my main launcher, waving goodbye to heavier alternatives.

Now I'll cut to the chase: I'm having an issue while attempting to use variables inside Aliases, and I was hoping someone could lend me a hand.

First of all, I'll say that I have a programming background, and I've read the Alias and Variables Help pages thoroughly, so I am aware of how variables are to be used (at least at a basic level). For example, I know that if a variable is defined as:

--- ---[myVar]
Then, said variable can be accessed via %uservar.myvar.hundred% from inside the Alias. I've created a test alias to illustrate how this would work. Here's the test configuration:

Fig1. Setup of an Alias that uses a raw variable
And here's how the test triggers the variable:

Fig2. Using the previous Alias. Please, note that the "hundred" string is actually
not necessary, it could've been any other string (or even empty)
So far so good. No issues here. My problem comes when I want to use a regular expression captured group to access a variable name. Here's where things get dirty:

Fig3. Setup of an Alias that uses a regex capture group as a variable
And here's where the problem that appears:the Alias does not seem to resolve the variable name (uservar.myvar.$$1) properly. When I try to use the alias from the launcher I get this error message of sorts:

Fig4. Using the regex'd Alias
My question being.... why is this not working!?!?!?!?!?

I am pretty sure that I know what the problem is in here: most likely, the Alias parser is looking for actual variable uservar.myvar.$$1, with the dollar symbols and all, which of course does not exist. But then comes the UI print function, which does indeed resolve the $$1 into "hundred" and thus spits the error message we see in Figure 4:

--- ---MISSINGUSERVAR:myvar.hundred
I'm gonna guess that I'm asking too deep of a question, but I'll cross my fingers and hope for an available quick fix for this issue. Maybe using 3 dollar symbols instead of 2? Putting it upside down and shaking it?  ;D

Thank you very much for such an amazing piece of software, and I'll see you around,

I don't know of any workaround to do exactly what you want to do. But perhaps mouser does.

Anyway I like that you're new to FARR but already push the boundaries :Thmbsup: Aliases are powerful so maybe there is is some other way to achieve the end goal you're after. Could you tell more about the use case?

Could you tell more about the use case?
-Nod5 (April 26, 2019, 04:29 PM)
--- End quote ---

Surely. What I am after is a simple UserName <--> UserID mapping when querying a URL.

Allow me to illustrate it with a practical example. Say, for example, that I own a webpage and every new user gets a numeric ID. After four new users have registered you end up with a UserName <--> UserID map like this one:

--- ---Alice is User 001
Bob is user 002
Carl is user 003
Daniel is user 004
Now, say that this webpage of mine allows you to access the user profile pages through an URL such as:

Where USERID is the number assigned to each user. So, if you wanted to access Daniel's profile you'd visit the following URL:

But in your day-to-day life you ain't gonna remember that Daniel is user "004", you will remember Daniel as Daniel!!! So what I want to do is to create a macro of sorts that takes in the real name of the user:

--- ---mykeyword Daniel
and then maps the user's name to the respective user ID, and builds the URL:

That's where my original post comes in. My idea around this issue would be to create a set of variables such as:

--- ---[myusers]
... and then I'd use a regular expression to capture the first parameter, which would then be fed to the following alias:

That'd be it!
To be completely honest I haven't given too much thought to the issue. Maybe the optimal solution doesn't use Aliases, or maybe I am overthinking the problem a little too hard. It just felt natural to me using a regular expression as a variable name (that is, abusing/assuming reflection). So I tried... and failed  :-[

Hi Xavi_8m, and welcome to the site  :Thmbsup:

I'm glad you are liking FARR -- you sure jumped right into the advanced stuff :)
I think I should be able to fix your problem -- sounds like it's just a matter of the order that FARR replaces variables and regex values, and that regex $$n values should be resolved first.

There are also alternative ways to do what you want, that might be less advanced but easier to maintain.
For example, FARR is very happy to let you make lists of items, either in an alias or even in a separate file, and then filter based on them.

So if you make an alias called "users" that just had a list of your users and their associated web urls like:

--- Code: Text ---alice | |
The advantage of doing it that "simpler" way is that you could type "users" and see a list of all your user urls, and then type "users b" to have it start filtering only users starting with b, or just type "users bob" and hit enter without thinking.  This also has the advantage of being less sensitive to spelling errors and helping you remember user names, etc.

There may be cases where using complex variables and regular expressions make sense, but it may be that sometimes just using a simple list of labeled results is cleaner.  You could also put that list in a text file and tell farr alias to grab the list from the text file so you could more easily update it outside of farr..


[0] Message Index

[#] Next page

Go to full version