3

I wonder if I can "send" a windowed program into a specific workspace when I start it via command line.

For example, I would like to start my computer with a certain number of windowed programs open in different workspaces. Is this possible? What are some basic concepts behind this?

I am using Unity, on Ubuntu 14.04.

I also tried to start gdevilspie but it seems to be affected by a bug.

thanks! :)

Glutanimate
  • 21,393
fstab
  • 135
  • 1
  • 8

2 Answers2

3

Using wmctrl, example gedit:

gedit & sleep 3; wmctrl -i -r `wmctrl -l -p | grep $! | awk '{ print $1 }'` -t 1
  • gedit & run gedit in backgroud
  • sleep 3 sleep for 3sec wait for window creation (my machine little bit slow)
  • $! return PID of previous command (ie: gedit pid)
  • wmctrl -l -p | grep PID | awk '{ print $1 }' get WID from gedit PID
  • wmctrl -i -r WID -t 1 move window with WID to 2nd desktop

Another way:

wmctrl -s 1 ; gedit & sleep 3; wmctrl -s 0;
  • Switch to 2nd desktop, launch gedit, wait 3sec; switch back to 1st desktop

Reference:

user.dz
  • 48,105
  • If you're using compiz the above don't work because you have one workspace with multiple viewports -- see https://askubuntu.com/a/41125/264966 – ndemou Jan 25 '18 at 17:22
0

It's basically the same @user.dz answered, just parametrized and instead of sleeping for 3 seconds for the windows handler to be created this one loops until find it.

# workspace target
_WS=3
export DISPLAY=:0 

gedit &
_PID="$!" 
_WID=""
while [[ $_WID == "" ]]; do
  _WID=$(wmctrl -l -p 2>/dev/null | grep $_PID | awk '{ print $1 }')
sleep 1
done

wmctrl -i -r $_WID -t $_WS