Tag: bash script

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:

gconftool-2 --get /apps/metacity/general/num_workspaces

You can set the number of workspaces with this command:

gconftool-2 --set -t int /apps/metacity/general/num_workspaces 6

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]

#!/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));

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.