@ulrich
Thanks for the tip on using split, I didn’t like any of the solutions so here is my generic one that supports up to 9 parameters (“cl1” to “cl9”). See the last commented out commands to see how to execute this macro from another (no need to copy/paste) as well as example command line parameters.
This takes from 0 to 3 parameters (all optional with defaults):
-
cmd_var1: This is used to pass the command line parameters, packed by the delimiter.
-
cmd_var2: Specifies the delimiter character(s). This is the backtick (“`”) by default.
-
cmd_var3: Specifies the value that should be placed into “cl1” to “cl9” if there are not enough supplied. This is an EMPTY string by default.
The following got a bit mangled (backticks removed for starters) so I have attached the source as a file.
GetCommandLineParameters().zip (1.4 KB)
{
"Name": "GetCommandLineParameters()",
"CreationDate": "2022-1-27",
"Commands": [
{
"Command": "store",
"Target": "fast",
"Value": "!replayspeed",
"Description": "Set the Replay speed to FAST"
},
{
"Command": "comment",
"Target": "Dennis Bareis v2022.01.27b #### GET PASSED VARIABLES in 'cmd_var2' (DELIMITED by 'cmd_var1') ####",
"Value": "",
"Description": "[EXAMPLE1]: ...&cmd_var1=821226`Some Name`0618 076 228`(09) 9647-0780`Somebody@gmail.com [EXAMPLE 2]: ...&cmd_var2=**&cmd_var3=NotSetOnCmdLine&cmd_var1=821226**Some Name**0618 076 228**(09) 9647-0780**Somebody@gmail.com"
},
{
"Command": "store",
"Target": "${!cmd_var1}",
"Value": "CmdLine",
"Description": "'!cmd_var2' contains all the parameters, they are split apart by occurances of '!cmd_var1'"
},
{
"Command": "if_v2",
"Target": "${!cmd_var2} == \"NOT_SET\"",
"Value": "",
"Description": "If its unspecified we will default to \"`'"
},
{
"Command": "store",
"Target": "`",
"Value": "CmdLineDel",
"Description": "Set the default delimiter as the caller didn't specify it."
},
{
"Command": "else",
"Target": "",
"Value": "",
"Description": ""
},
{
"Command": "store",
"Target": "${!cmd_var2}",
"Value": "CmdLineDel",
"Description": "Get the delimiter, make this a single 'unlikely' character or as many characters as you wish to ensure it is unique"
},
{
"Command": "end",
"Target": "",
"Value": "",
"Description": ""
},
{
"Command": "if_v2",
"Target": "${!cmd_var3} == \"NOT_SET\"",
"Value": "",
"Description": "If its unspecified we will default to \"\""
},
{
"Command": "store",
"Target": "",
"Value": "CmdLineDef",
"Description": "Set the default value for unspecified command line parameters (defaults to empty string)."
},
{
"Command": "else",
"Target": "",
"Value": "",
"Description": ""
},
{
"Command": "store",
"Target": "${!cmd_var3}",
"Value": "CmdLineDef",
"Description": "Get the default value for unspecified parameters (the user specified it)"
},
{
"Command": "end",
"Target": "",
"Value": "",
"Description": ""
},
{
"Command": "store",
"Target": "true",
"Value": "!ErrorIgnore",
"Description": "Don't stop script if there are not enough parameters from the command line"
},
{
"Command": "store",
"Target": "${CmdLineDef}",
"Value": "cl1",
"Description": "Set default value (empty string by default)"
},
{
"Command": "store",
"Target": "${CmdLineDef}",
"Value": "cl2",
"Description": "Set default value (empty string by default)"
},
{
"Command": "store",
"Target": "${CmdLineDef}",
"Value": "cl3",
"Description": "Set default value (empty string by default)"
},
{
"Command": "store",
"Target": "${CmdLineDef}",
"Value": "cl4",
"Description": "Set default value (empty string by default)"
},
{
"Command": "store",
"Target": "${CmdLineDef}",
"Value": "cl5",
"Description": "Set default value (empty string by default)"
},
{
"Command": "store",
"Target": "${CmdLineDef}",
"Value": "cl6",
"Description": "Set default value (empty string by default)"
},
{
"Command": "store",
"Target": "${CmdLineDef}",
"Value": "cl7",
"Description": "Set default value (empty string by default)"
},
{
"Command": "store",
"Target": "${CmdLineDef}",
"Value": "cl8",
"Description": "Set default value (empty string by default)"
},
{
"Command": "store",
"Target": "${CmdLineDef}",
"Value": "cl9",
"Description": "Set default value (empty string by default)"
},
{
"Command": "executeScript_Sandbox",
"Target": "return ${CmdLine}.split(${CmdLineDel})[0].trim();",
"Value": "cl1",
"Description": "SET [cl1]: Command line parameter #1"
},
{
"Command": "executeScript_Sandbox",
"Target": "return ${CmdLine}.split(${CmdLineDel})[1].trim();",
"Value": "cl2",
"Description": "SET [cl2]: Command line parameter #2"
},
{
"Command": "executeScript_Sandbox",
"Target": "return ${CmdLine}.split(${CmdLineDel})[2].trim();",
"Value": "cl3",
"Description": "SET [cl3]: Command line parameter #3"
},
{
"Command": "executeScript_Sandbox",
"Target": "return ${CmdLine}.split(${CmdLineDel})[3].trim();",
"Value": "cl4",
"Description": "SET [cl4]: Command line parameter #4"
},
{
"Command": "executeScript_Sandbox",
"Target": "return ${CmdLine}.split(${CmdLineDel})[4].trim();",
"Value": "cl5",
"Description": "SET [cl5]: Command line parameter #5"
},
{
"Command": "executeScript_Sandbox",
"Target": "return ${CmdLine}.split(${CmdLineDel})[5].trim();",
"Value": "cl6",
"Description": "SET [cl6]: Command line parameter #6"
},
{
"Command": "executeScript_Sandbox",
"Target": "return ${CmdLine}.split(${CmdLineDel})[6].trim();",
"Value": "cl7",
"Description": "SET [cl7]: Command line parameter #7"
},
{
"Command": "executeScript_Sandbox",
"Target": "return ${CmdLine}.split(${CmdLineDel})[7].trim();",
"Value": "cl8",
"Description": "SET [cl8]: Command line parameter #8"
},
{
"Command": "executeScript_Sandbox",
"Target": "return ${CmdLine}.split(${CmdLineDel})[8].trim();",
"Value": "cl9",
"Description": "SET [cl9]: Command line parameter #9"
},
{
"Command": "echo",
"Target": "CMDLINE: #1=${cl1}, #2=${cl2}, #3=${cl3}, #4=${cl4}, #5=${cl5}, #6=${cl6}, #7=${cl7}, #8=${cl9}, #9=${cl9} [DEL=${CmdLineDel}, DEFAULT-EMPTY=${CmdLineDef}]",
"Value": "",
"Description": ""
},
{
"Command": "store",
"Target": "false",
"Value": "!ErrorIgnore",
"Description": "Back to normal state, STOP SCRIPT ON ERROR"
},
{
"Command": "store",
"Target": "true",
"Value": "!STATUSOK",
"Description": "We don't care about any previous errors"
},
{
"Command": "comment",
"Target": "pause // ",
"Value": "",
"Description": ""
},
{
"Command": "comment",
"Target": "run // GetCommandLineParameters()",
"Value": "",
"Description": "### HOW TO CALL THIS #### Get Command Line Parameters into cl1 ~ cl9"
}
]
}