swaymsg(1)
Send messages to a running Sway window manager instance and receive responses.
Synopsis
swaymsg [OPTION] [MESSAGE]Description
swaymsg is a command-line utility for communicating with the Sway window manager via its IPC (Inter-Process Communication) socket. It allows you to query and control Sway's state, execute commands, and retrieve information about windows, workspaces, and outputs.
Messages are sent using Sway's command syntax. You can run arbitrary Sway commands, subscribe to events, and get detailed JSON responses about the current state of your desktop environment.
Common options
| Flag | What it does |
|---|---|
-h, --help | Show help message and exit |
-q, --quiet | Suppress output of the response message |
-r, --raw | Output raw JSON response without formatting |
-s, --socket PATH | Use a specific Sway socket instead of auto-detecting |
-t, --type TYPE | Specify message type (command, get_tree, get_marks, etc.) |
-m, --monitor | Monitor and display Sway events (subscribe mode) |
Examples
Switch to workspace 2
swaymsg 'workspace 2'Focus the window to the left of the current one
swaymsg 'focus left'Get the window tree and extract output names
swaymsg -t get_tree | jq '.nodes[].name'List all workspaces and their details in JSON format
swaymsg -t get_workspacesSet output resolution for a specific monitor
swaymsg 'output HDMI-1 resolution 2560x1440@60Hz'Monitor and display all window-related events in real-time
swaymsg -m 'subscribe ["window"]' | jq .Launch Firefox without printing the response
swaymsg -q 'exec firefox'Toggle between split and tabbed window layouts
swaymsg 'layout toggle split tabbed'