Many X applications allow you to specify geometry, like this:
Which is great. But it doesn’t let you specify what desktop you want the application to open on.
For a while, in GNOME 3, I used the Auto Move Windows extension, which moves all windows of a given application to a particular workspace. The limitation with this approach is that it affects all windows of a given application and can’t be specified per application launch (which is not so useful for, say, terminals!)
So I wrote a script to do what I wanted. You simply pass the script a desktop (which is a zero-based index) and the command to launch. E.g.:
Here’s the script. It works by launching the process then polling the X-server for any windows that are owned by that process 10 times a second for 10 seconds. If it finds one, it moves it to the specified workspace.
APP=`basename "$0"`
die()
{
echo $APP: "$@" >&2
exit 1
}
usage()
{
echo 'usage: '$APP' WORKSPACE CMD [ARG]...'
echo
echo 'WORKSPACE is the zero-based index of the workspace'
exit 1
}
# check wmctrl is available
[[ -x `which wmctrl` ]] || die "please install wmctrl"
# we should have at least 2 args
[[ -n "$2" ]] || usage
# check workspace
WS=$1
[[ $(( 0 + $WS )) -gt 0 || "$WS" == "0" ]] || usage
shift
# launch program
"$@" &
CPID=$!
# look for the window every 0.1 seconds for 10 seconds
for (( A = 0; A < 100; A++ )); do
sleep 0.1
# has child process terminated?
[[ -d /proc/$CPID ]] || break
# try to find process's window ID
WID=`wmctrl -lp | \
egrep '^0x[0-9a-f]+ +[-0-9]+ +'$CPID' ' | \
awk '{print $1}'`
if [[ -n "$WID" ]]; then
# move the window
wmctrl -ir $WID -t $WS
break
fi
done
# failed?
[[ $A -eq 100 ]] && die "couldn't find application's window..."
A zero-based index, eh?
Indeed. :o)
Nice idea.
If I wanted to run gnome-terminal on workspace 2 would I type:
./script start-on-workspace 2 gnome-terminal ?
Almost. More like…