Hi!
I'm having troubles executing a perl-script using variables for a range of characters (or don't really know what to call it).
My situation is that I'm trying to create a macro that based on a prompt will type/past a string of random characters, based on what the prompt returns.
Image of Prompt Action for clarification of what I am trying to do:
The prompt in itself and the if-statements it needs to work as I want is not really the problem. What I am struggling whit is getting the perl-script to behave well with the KMVARiables I am feeding it based on the prompt/if-statements.
The following perl-script works perfectly in of itself:
perl -e '@c=((0..9),("A".."Z"),("a".."z"),("~","!","@","%","^","&","*","(",")","-","_","+","=","{","}","[","]","|",":",";","<",">","?","/","#"));$p.=$c[rand(scalar @c)] for 1..16; print "$p\n"'
Returning a random string of 16 characters like this:
M6q8lvE(_5y=*Fp2
But when adding variables to the script like this I am having problems:
perl -e '@c=(($ENV{KMVAR_RndNumbers}),($ENV{KMVAR_RndUppercase}),($ENV{KMVAR_RndLowercase}),($ENV{KMVAR_RndSpecial}));$p.=$c[rand(scalar @c)] for 1..$ENV{KMVAR_Number_of_caracters}; print "$p\n"'
Getting this abomination of a string of 16 groups of characters:
“A”..”Z”0..90..9”a”..”z””~”,”!”,”@“,”%”,”^”,”&”,”*”,”(“,”)”,”-“,”_”,”+”,”=“,”{“,”}”,”[“,”]”,”|”,”:”,”;”,”<“,”>”,”?”,”/“,”#”0..9”A”..”Z”0..90..9”~”,”!”,”@“,”%”,”^”,”&”,”*”,”(“,”)”,”-“,”_”,”+”,”=“,”{“,”}”,”[“,”]”,”|”,”:”,”;”,”<“,”>”,”?”,”/“,”#”0..90..9”a”..”z””a”..”z””A”..”Z””A”..”Z”
To clarify: Each of the 16 groups consists of either 0..9
, "A".."Z"
, "a".."z"
or "~","!","@","%","^","&","*","(",")","-","_","+","=","{","}","[","]","|",":",";","<",">","?","/","#"
, instead of returning 16 instances of a character form any of these groups (1
, 2
, 3
, A
, B
, C
, a
, b
, c
, ~
, !
, @
, etc.).
I've searched around here for ways to use KMVARiables within shell scrips but haven't been able to find any information about this specific issue. I have also tried combining the variables into one (see example macros bellow) but haven't been able to get this to work either.
Anyone having any ideas on how to tackle this problem?
RandomString (Combined) Macro (v10.2)
RandomString (Combined).kmmacros (8.2 KB)