Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Swap i3 displays / workspaces between displays
#!/usr/bin/env bash
# requires jq
DISPLAY_CONFIG=($(i3-msg -t get_outputs | jq -r '.[]|"\(.name):\(.current_workspace)"'))
for ROW in "${DISPLAY_CONFIG[@]}"
read -ra CONFIG <<< "${ROW}"
if [ "${CONFIG[0]}" != "null" ] && [ "${CONFIG[1]}" != "null" ]; then
echo "moving ${CONFIG[1]} right..."
i3-msg -- workspace --no-auto-back-and-forth "${CONFIG[1]}"
i3-msg -- move workspace to output right
Copy link

mark2185 commented Apr 28, 2022

i3 v4.20.1 throws an error for this:

i3-msg -- output primary
ERROR: Your command: output primary
ERROR:               ^^^^^^^^^^^^^^
ERROR: Expected one of these tokens: <end>, '[', 'move', 'exec', 'exit', 'restart', 'reload', 'shmlog', 'debuglog', 'border', 'layout', 'append_layout', 'workspace', 'focus', 'kill', 'open', 'fullscreen', 'sticky', 'split', 'floating', 'mark', 'unmark', 'resize', 'rename', 'nop', 'scratchpad', 'swap', 'title_format', 'title_window_icon', 'mode', 'bar', 'gaps'
[{"success":false,"parse_error":true,"error":"Expected one of these tokens: <end>, '[', 'move', 'exec', 'exit', 'restart', 'reload', 'shmlog', 'debuglog', 'border', 'layout', 'append_layout', 'workspace', 'focus', 'kill', 'open', 'fullscreen', 'sticky', 'split', 'floating', 'mark', 'unmark', 'resize', 'rename', 'nop', 'scratchpad', 'swap', 'title_format', 'title_window_icon', 'mode', 'bar', 'gaps'","input":"output primary","errorposition":"^^^^^^^^^^^^^^"}]

And I've found it's not needed at all, the i3-msg -- workspace "${ACTIVE_WS}" will switch to the output anyway.

But it also needs --no-auto-back-and-forth in order to work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment