PDA

View Full Version : [SOLVED] Switch to virtual desktop with shell command?



lunix2
April 24th, 2014, 07:51 AM
Is there a bash command to switch to a numbered virtual desktop? I have four virtual desks. What would I type into bash to switch to desktop number 3, for example?

Lars Noodén
April 24th, 2014, 07:59 AM
You can install the packag wmctrl (http://manpages.ubuntu.com/manpages/trusty/en/man1/wmctrl.1.html) and use that to switch. The count starts at 0 so to get to the third virtual desktop you would usewmctrl -s 2 That works in Lubuntu, so it might work also in Ubuntu.

lunix2
April 24th, 2014, 09:29 AM
BEAUTIFUL! Many thanks!

grumblebum2
April 24th, 2014, 05:17 PM
As you say virtual desktops I assume you are using compiz in which case you really only have 1 desktop so the wmctrl
command won't work.
You would have to use wmctrl -o with x,y values to change to a specific workspace.

With compiz each added virtual desktop increases these values by your screen resolution.

eg Using my resolution(1680x1050) and 4 horizontal desktops these commands will switch...

wmctrl -o 0,0
wmctrl -o 1680,0
wmctrl -o 3360,0
wmctrl -o 5040,0


This command will give each of your x,y values, when run in a terminal on that particular desktop.

wmctrl -d | awk '{print $6}'

lunix2
April 24th, 2014, 07:41 PM
Thanks for your answer. Fortunately, the simpler syntax worked for me. Though I do use vritual desktops, each spanning two monitors wide. I certainly appreciate the time and effort you put into helping me. I should've marked this as "solved", something I just found out about. Now if I could just see where to do that. I'll get it.