CLI Parameters
Desk Switcheroo accepts command-line arguments for querying virtual-desktop state and for controlling a running instance. The command-line interface is implemented in includes/CLI.au3 and dispatched from desktop_switcher.au3 at startup. For editing settings instead, see Configuration and the Advanced INI Reference.
Command forms
A command is a single token with one of three interchangeable prefixes — --, -, or /:
desk_switcheroo.exe --get-current
desk_switcheroo.exe -get-current
desk_switcheroo.exe /get-current
The parser (_CLI_ParseArgs) strips the prefix, lowercases the command, and reads up to two following tokens as arguments (a token starting with - or / is treated as the next flag, not an argument). A quoted argument that contains spaces is passed through as one value, which is how --rename takes a label:
desk_switcheroo.exe --rename 2 "Work"
The legacy -autostart flag is ignored by the CLI parser (it is handled separately by the app’s start-with-Windows path), so it never counts as a command.
Query commands
Query commands read state and print to standard output. They run standalone — the process starts, executes the query locally (_CLI_ExecuteLocal), prints the result, and exits immediately, whether or not a widget is already running. They are handled on an early read-only path that runs before the singleton block (see dispatch behavior), so querying the executable never disturbs a running widget.
| Command | Output |
|---|---|
--help | Full usage text. |
--version | The application version string, one line. |
--list-desktops | One line per desktop: N: label. |
--get-current | The current desktop number, one line. |
--status | A JSON object: {"current":N,"count":M,"desktops":[{"id":1,"name":"…"},…]}. |
The --status JSON is built by hand in __CLI_PrintStatus and escapes \ and " in labels, so it is safe to pipe into a JSON parser.
Action commands
Action commands change desktop state. They are recognized by the parser and defined for delivery to a running instance over the app’s WM_COPYDATA IPC channel (see below).
| Command | Args | Effect |
|---|---|---|
--goto N | desktop number (1-based) | Switch to desktop N. |
--next | — | Switch to the next desktop (honors wrap_navigation). |
--prev | — | Switch to the previous desktop (honors wrap_navigation). |
--add-desktop | — | Create a new virtual desktop. |
--remove-desktop N | desktop number | Remove desktop N (and shift labels). |
--rename N "label" | number + label | Rename desktop N. |
--move-window N | desktop number | Move the currently active window to desktop N. |
--toggle-list | — | Show/hide the desktop list panel. |
--toggle-slideshow | — | Start/stop the desktop slideshow. (--toggle-carousel is accepted as a deprecated alias for the same action.) |
--load-profile "name" | profile name | Load a saved profile. |
--save-profile "name" | profile name | Save the current state as a profile. |
--goto, --remove-desktop, --rename, and --move-window validate their arguments and print an error (and, for an unknown command, the help text) if the number is missing or out of range.
The IPC channel
A running instance creates a hidden window titled DeskSwitcheroo_IPC and registers a WM_COPYDATA handler (_CLI_RegisterIPC → _CLI_HandleIPC). Messages are accepted only when the COPYDATASTRUCT.dwData field equals the magic value 0x44534B (ASCII “DSK”); the payload is the command string (for example goto 3 or rename 2 Work). On receipt, navigation and desktop-management commands are executed directly, while the GUI-level commands (toggle-list, toggle-slideshow, load-profile, save-profile) are queued and then consumed on the next main-loop pass by _ProcessIPCPending, which drains _CLI_CheckIPCPending and dispatches them through the same handlers the tray and hotkeys use. That drain also runs while the Settings dialog is open, so a relayed GUI command takes effect even then. This is a stable contract an external tool can target to drive a running widget.
How the executable dispatches its own command line
When you run desk_switcheroo.exe with a command, the startup path in desktop_switcher.au3 handles it as follows:
- Action commands are relayed to a running instance. Before the singleton block (which would otherwise kill the running widget) and before the new process registers its own IPC window, the startup path calls
_CLI_SendToRunning, which locates the running instance’sDeskSwitcheroo_IPCwindow and sends the command overWM_COPYDATA. If a running instance is found, the command is delivered and the launching process exits0without starting a second widget. Sodesk_switcheroo.exe --goto 3now switches the already-running widget to desktop 3. - Action commands with no running instance to relay to fall through and execute locally against the OS (
_CLI_ExecuteLocal), then exit. Because virtual desktops are global to the session, the desktop operations —goto,next,prev,add-desktop,remove-desktop,rename, andmove-window— work standalone and exit0on success. The GUI-only actions —toggle-list,toggle-slideshow,load-profile, andsave-profile— need a widget to drive, so with no instance running they print a “requires a running instance” error and exit1rather than spawning a persistent widget as a side effect. - Query commands are handled on an early read-only path that runs before the singleton block. The process initializes only what a query needs — config, i18n, and the VirtualDesktopAccessor DLL (read-only calls; Labels are read with OS-name sync disabled so nothing is written) — then calls
_CLI_ExecuteLocaland exits. Because this happens before the singleton block, a query never kills the running widget. If the DLL cannot be loaded,--list-desktops/--get-current/--statusdegrade gracefully to reporting a single desktop rather than failing.
Note: earlier builds ran queries after the singleton block, so launching the executable for a query (for example
desk_switcheroo.exe --get-current) killed the running widget as a side effect, and--statusreported the DLL fallback of one desktop because it ran before the DLL was initialized. Both are fixed: queries now run on the early read-only path above, so they leave a running widget untouched and report the real desktop count.
Scripting examples
Query commands, which are the standalone-safe ones, compose cleanly in PowerShell:
# Current desktop number
$current = & .\desk_switcheroo.exe --get-current
# Parse the JSON status
$status = & .\desk_switcheroo.exe --status | ConvertFrom-Json
Write-Host "On desktop $($status.current) of $($status.count)"
# List desktops
& .\desk_switcheroo.exe --list-desktops
Exit behavior
For a query command, the process runs the query and exits (exit code 0 on success; the query helpers return False and print an error for bad input). If VirtualDesktopAccessor.dll cannot be loaded, the app exits with code 1 before any command runs. When no recognized command is present, the app starts normally as the widget.