Purpose:Monitor USB device connection and disconnection

 

Format:USBMONITOR [/C [name]]

USBMONITOR [/=] name CONNECTED | DISCONNECTED n command

 

nameDevice name
nNumber of repetitions (or FOREVER)
commandCommand to execute when condition is triggered

 

/C(lear)

 

Usage:

 

The USB device name can include wildcards. You can use either the device ID or the "friendly" name for the device.

 

The command line will be parsed and expanded before USBMONITOR is executed, so if you want to pass redirection characters or variables to command you will need to protect them (by enclosing in single back quotes, doubling the %'s, or using command grouping).

 

If the last argument on the line is a single (, it is interpreted as the beginning of a command group. USBMONITOR will append the following lines (in a batch file) or prompt you for more input (at the command line) until it gets a closing ).

 

If you don't enter any arguments, USBMONITOR will display the USB devices it is currently monitoring.

 

The monitoring runs asynchronously in a separate thread. When the condition is triggered, the command will be executed immediately. This may cause problems if you try to write to the display or access files while the main TCC thread is also performing I/O. You may need to use START or DETACH in command to avoid conflicts.

 

USBMONITOR creates two environment variables when a device is connected or disconnected that can be queried by command. The variables are deleted after command is executed.

 

_usbdeviceidThe device ID (this will usually have special characters like & in the name, so you will probably need to use double quotes around the variable name to prevent TCC from parsing the special characters)

 

_usbnameThe "friendly" name of the device

 

There is another variable that is updated after each trigger:

 

_usbcountThe number of times the command has been triggered

 

Options:

 

/=Display the USBMONITOR command dialog to help you set the command line options. The /= option can be anywhere on the line; additional options will set the appropriate fields in the command dialog.

 

/CIf name is specified, remove the monitor for that USB device. Otherwise, remove all USB monitors.