Programmatically Adding Workspaces in Gnome

If you ever need to add or remove Gnome workspaces using a command-line or a keyboard shortcut, here are the basics required to get it going. Gconf is Gnome’s configuration system. It keeps track of many of your computers settings.

The commands

You can see how many workspaces your desktop currently has using this command:

[code=bash]gconftool-2 –get /apps/metacity/general/num_workspaces[/code]

You can set the number of workspaces with this command:

[code=bash]gconftool-2 –set -t int /apps/metacity/general/num_workspaces 6[/code]

Just change the “6” to the number of workspaces you need. You can increase it to add workspaces, or decrease it to destroy workspaces. Applications in a removed workspace shift left to the first active workspace.

Making it into a command

Below is a command I wrote to easily add ore remove one workspace. Usage: workspace [-add|-remove]

[code=bash]
#!/bin/bash

case “$1” in
“-add”    ) method=”+”;;
“-remove” ) method=”-“;;
*         ) echo “Usage: workspace [-add|-remove]”; exit $E_WRONGARGS;;
esac

gconftool-2 –set -t int /apps/metacity/general/num_workspaces $((`gconftool-2 –get /apps/metacity/general/num_workspaces`${method}1));
[/code]
You can now use it on the command line and/or make a keyboard shortcut to call the script.

I tested this in Ubuntu 10.10, but it should work in any Linux distribution using a recent version of Gnome.

One Reply to “Programmatically Adding Workspaces in Gnome”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.