LinuxCommandLibrary

swaymsg

Send IPC commands to Sway compositor

TLDR

Send command

$ swaymsg [command]
copy
Get workspaces
$ swaymsg -t get_workspaces
copy
Get outputs
$ swaymsg -t get_outputs
copy
Get focused window
$ swaymsg -t get_tree | jq '.. | select(.focused?)'
copy
Reload configuration
$ swaymsg reload
copy
Exit sway
$ swaymsg exit
copy
Move workspace
$ swaymsg move workspace to output [HDMI-A-1]
copy

SYNOPSIS

swaymsg [-t type] [-m] [options] message

DESCRIPTION

swaymsg is the IPC (Inter-Process Communication) client for the Sway Wayland compositor. It sends commands and queries to a running Sway instance via the IPC socket, enabling scripted control of window management operations like moving, resizing, and focusing windows.
Query message types (getworkspaces, getoutputs, get_tree) return JSON data describing the current compositor state, which can be parsed with tools like jq. This makes swaymsg useful for building custom status bars, automation scripts, and workspace management tools.
Monitor mode subscribes to Sway events and prints them in real time, useful for debugging and building reactive scripts. The IPC socket path defaults to the SWAYSOCK environment variable set by Sway.

PARAMETERS

-t, --type TYPE

Message type.
-m, --monitor
Monitor for responses.
-r, --raw
Raw output.
-q, --quiet
Quiet mode.
-s, --socket PATH
Socket path.

MESSAGE TYPES

get_workspaces - List workspaces
get_outputs - List outputs
get_tree - Window tree
get_marks - Window marks
get_bar_config - Bar config
get_version - Sway version

CAVEATS

Sway must be running. Socket permissions required. JSON output needs parsing.

HISTORY

swaymsg is the IPC client for Sway compositor. It mirrors i3-msg functionality for Wayland.

SEE ALSO

sway(1), jq(1), i3-msg(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community