Skip to content

Instantly share code, notes, and snippets.

@tokland
Last active February 22, 2022 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tokland/834f9d5dd261bb2d1b3725df705619cd to your computer and use it in GitHub Desktop.
Save tokland/834f9d5dd261bb2d1b3725df705619cd to your computer and use it in GitHub Desktop.
#!/bin/bash
# Start a UI app and move its window to a specific Xfce workspace.
#
# Example: Move app xoscope to workspace number 2 (starts at 1).
#
# $ run-in-workspace 2 xoscope
run_in_workspace() {
local workspace=$1
local pid winh
shift 1
"$@" &
pid=$!
echo "pid: $pid"
while true; do
winh="$(wmctrl -l -p | awk "\$3 == $pid" | awk '{print $1}')"
echo "Winh0: $winh"
if test -z "$winh"; then
sleep 0.1
else
wmctrl -i -r "$winh" -t "$((workspace - 1))"
break
fi
done
}
run_in_workspace "$@"
@spogelse
Copy link

spogelse commented Jan 7, 2021

Nice idea. To allow for multiple windows, consider:

wmctrl -l -p | awk "\$3 == $pid" | awk '{print $1}' | while read winh; do
    # do stuff with $winh
done

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