← Back to Docs

Command Examples

WorkTop runs every Action command through cmd.exe. The examples below use the same syntax you would type into a Command Prompt window. Pipes, redirects, environment variables, and quoted paths with spaces all work as expected.

For an overview of how Actions work, see Actions. For multi-desktop scripting from a single Action, see Scripting with variables.

Open a file in its default app

  • Command: start "" "C:\Users\me\Documents\todo.md"

The empty "" after start is the window title argument. It is required when the path itself is quoted, otherwise start treats the path as the title.

Open a URL in your default browser

  • Command: start "" "https://github.com"

Launch an app

For apps installed under Program Files, quote the path and keep the empty title for start:

  • Command: start "" "C:\Program Files\Mozilla Firefox\firefox.exe"

For apps on your PATH (for example code for VS Code with the PATH option installed), the exe name alone is enough:

  • Command: code "C:\projects\my-app"

Run a batch file

  • Command: C:\scripts\setup-work.bat

Arguments work the same way as on the command line:

  • Command: C:\scripts\setup-work.bat dev fast

Quote any argument that contains spaces, e.g. C:\scripts\backup.bat "C:\My Documents".

Run a PowerShell one-liner

  • Command: powershell -NoProfile -Command "Get-Date | Out-File $env:TEMP\last-switch.txt"

-NoProfile skips your PowerShell profile for faster, more predictable startup.

Run a PowerShell script file

  • Command: powershell -NoProfile -ExecutionPolicy Bypass -File "C:\scripts\on-switch.ps1"

-ExecutionPolicy Bypass sidesteps PowerShell's signing policy for this one invocation. Use it if your script isn't signed.

Working directory

Set the Working directory field when your command needs to run in a specific folder. Equivalent to cd-ing there first. Useful when you want the same command to resolve relative paths differently per desktop. For example, opening a desktop-specific notes file:

  • Command: start "" notes.md
  • Working directory: C:\Users\me\OneDrive\WorkNotes

Do not quote the Working directory path even if it contains spaces. The field is a raw filesystem path, not a shell argument. C:\Program Files\Mozilla Firefox works. "C:\Program Files\Mozilla Firefox" does not.

Pipes and redirects

Pipes (|), redirects (>, >>), and chaining (&&, ||) behave the same as in a Command Prompt window.

  • Command: echo Switched at %TIME% >> %TEMP%\worktop.log

Using variables

{from_name}, {to_name}, {from_id}, and {to_id} are substituted before the command runs.

  • Command: echo Now on {to_name} >> %TEMP%\worktop.log

To make one Action behave differently per desktop, see Scripting with variables.

Stopping a service

  • Command: net stop spooler

Most service operations require administrator rights. If WorkTop is not running elevated, the command will fail. Click Test command in the Action form to see the exit code and any error output.

Tips

  • Click Test command in the Action form to run the command once and see the result before saving.
  • Quote any path or argument that contains spaces. Normal Windows path quoting rules apply.
  • Raise the timeout for commands that may take a while. The default is 30 seconds.
  • If a command does not behave the same when WorkTop runs it as it does when you type it into cmd directly, check the Test command output for the exit code and stderr.