Handbook Page ID 24

Command Macro

You can prepare a text file with list of command lines and play the file via Token2Shell. The connected remote system will see the played file as command lines that were typed and sent by you. Token2Shell also supports a set of wait/send style script commands.

Script Commands

When you create a macro file, its content is interpreted by line. A text line ends with <CR><LF> control characters and Token2Shell removes heading and trailing white spaces.

For each line, if the line starts with a "#" character, Token2Shell tries interpret the line as a macro command and its arguments. If it fails, the line is sent as it is along with line-end characters. The line-end characters are determined from the current session states.

// sends "abc"
#send "abc"

If you wish Token2Shell to interpret the line starting with "#" as a normal character, use two "#" characters.

// sends "#send "abc"" and line-end characters
##send "abc"
Token2Shell supports the following commands:

  • #sendwait line_send_interval_in_milliseconds

    Sets the interval between sending each non-command line text. If line_send_interval_in_milliseconds is preceded with a minus(-) character, the sending is paused until there is no incoming data for line_send_interval_in_milliseconds.

    When a macro file is loaded, the sending interval is set to -300 milliseconds, i.e., the next line is sent when there is no incoming data for 300 milliseconds.

  • #wait wait_time_in_milliseconds

    Pauses the macro processing for wait_time_in_milliseconds.

    If wait_time_in_milliseconds is preceded with a minus(-) character, the processing is paused until there is no incoming data for wait_time_in_milliseconds.

    // Wait for 3 seconds.
    #wait 3000
    
    // Wait until there is no incoming data for 2 seconds.
    #wait -2000
    
  • #send "string"

    Sends "string" (without the quotation marks).
    Line-end characters are not automatically sent.

  • #waitfor "string"

    Monitors the incoming data stream and waits until the "string" appears.


NOTES

You can use the following escape sequence to insert control or special characters in a "string":

Escape Seq.Hex Value
\\0x5C'\' character itself
\b0x08<Backspace>
\t0x09<Tab>
\n0x0A<LF>
\r0x0D<CR>
\e0x1B<ESC>
\x{HEX} {HEX} is interpreted as a HEX value of the character.
Ex.) \x09 denotes <Tab> control character.