Occasionally, I will want to make an alias where I want the argument (wildcard) to be optional. Currently, this would require two aliases, if you want to do it the simple way:
However, you can achieve the desired effect with an alias set to recognize regular expressions. (One of the checkboxes on the alias configuration screen).
The following alias string would accept an argument, but not require one:
Stretched out, this is what the syntax means:
Now, in the script file you call, it might look like this (in Visual Basic Script):
In that example, you might decide to set a default value if no argument was provided.
I've found that with clever programming, I can reduce the number of aliases I have by consolidating them into 'advanced' aliases using features like in the example above. :)
- One alias without the wildcard: dothat
- Another alias with the wildcard: dothat *
However, you can achieve the desired effect with an alias set to recognize regular expressions. (One of the checkboxes on the alias configuration screen).
The following alias string would accept an argument, but not require one:
^dothat([ ]+(.*))?$
Stretched out, this is what the syntax means:
^ : The alias must start at the beginning of a line.
[ ]+ : Accept one or more space characters.
(.*) : Accept a wildcard of any length.
(exp)? : The circle brackets are used to wrap the expression inside as an element to be acted upon.
The ? after the brackets indicates accept 0 or more matches of that expression.
$ : The alias line must end here. If there were more unexpected text on the line, the alias would not match.
Now, in the script file you call, it might look like this (in Visual Basic Script):
Sub dothat (Aliasname, Aliasline, Wildcards)
Dim Argument
Argument = Trim(Wildcards(1))
If Argument = Empty Then Argument = "Default Value"
World.Send "do this"
World.Send "do this next"
World.Send "do that " & Argument
End Sub
* The Trim function gets rid of leading or trailing space characters.
In that example, you might decide to set a default value if no argument was provided.
I've found that with clever programming, I can reduce the number of aliases I have by consolidating them into 'advanced' aliases using features like in the example above. :)