← 返回命令列表

Linux command

swaymsg 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Send command

swaymsg [command]

Get workspaces

swaymsg -t get_workspaces

Get outputs

swaymsg -t get_outputs

Get focused window

swaymsg -t get_tree | jq '.. | select(.focused?)'

Reload configuration

swaymsg reload

Exit sway

swaymsg exit

Move workspace

swaymsg move workspace to output [HDMI-A-1]

说明

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 (get_workspaces, get_outputs, 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.

参数

-t, --type _TYPE_
Message type.
-m, --monitor
Monitor for responses until killed. Can only be used with the subscribe message type.
-p, --pretty
Use pretty output even when not using a tty.
-r, --raw
Use raw JSON output even when using a tty.
-q, --quiet
Send the IPC message but do not print the response.
-s, --socket _PATH_
Use the specified socket path instead of SWAYSOCK environment variable.

FAQ

What is the swaymsg command used for?

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 (get_workspaces, get_outputs, 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.

How do I run a basic swaymsg example?

Run `swaymsg [command]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -t, --type _TYPE_ do in swaymsg?

Message type.