$linuxjunkies
>

swaymsg(1)

Send messages to a running Sway window manager instance and receive responses.

UbuntuDebianFedoraArch

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

FlagWhat it does
-h, --helpShow help message and exit
-q, --quietSuppress output of the response message
-r, --rawOutput raw JSON response without formatting
-s, --socket PATHUse a specific Sway socket instead of auto-detecting
-t, --type TYPESpecify message type (command, get_tree, get_marks, etc.)
-m, --monitorMonitor 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_workspaces

Set 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'

Related commands