Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm using the Compiz Workspace Naming plugin, and I can change workspace names through ccsm just fine right now. However, I'd like to be able to change the active workspace's name from the command line, without having to launch ccsm and navigate the menu.

I used to be able to do this using wnck, and this function in my bashrc:

function wsname {
  python -c "import wnck; s = wnck.screen_get_default(); s.force_update();\
    s.get_active_workspace().change_name('$*')"
}
share|improve this question

1 Answer 1

I figured out that the names can be set using

gsettings set org.compiz.workspacenames:/org/compiz/profiles/unity/plugins/workspacenames/ names [\"Name1\",\"Name3\"]
gsettings set org.compiz.workspacenames:/org/compiz/profiles/unity/plugins/workspacenames/ viewports [1,3]

So I wrote a python script to do what I wanted:

#!/usr/bin/python
import sys
from subprocess import Popen, PIPE

getoutput = lambda x: Popen(x, stdout=PIPE).communicate()[0]
listIntOutput = lambda x: "[%s]" % ",".join([str(i) for i in x])
listStrOutput = lambda x: "[%s]" % ",".join(["\"%s\"" % s for s in x])
SCHEMA = \
  "org.compiz.workspacenames:/org/compiz/profiles/unity/plugins/workspacenames/"

if len(sys.argv) < 2:
  name = ""
else:
  name = " ".join(sys.argv[1:])

# get the position of the current workspace
ws = list(int(i.strip(",")) for i in  getoutput(("xprop", "-root",
    "-notype", "_NET_DESKTOP_VIEWPORT")).split()[-2:])
# get the number of horizontal and vertical workspaces
hsize = int(getoutput(("gconftool",
    "--get", "/apps/compiz-1/general/screen0/options/hsize")))
vsize = int(getoutput(("gconftool",
    "--get", "/apps/compiz-1/general/screen0/options/vsize")))
# get the dimentions of a single workspace
x, y = list(int(i) for i in getoutput(("xwininfo", "-root",
    "-stats", )).split("geometry ")[1].split("+")[0].split("x"))
# enumerate workspaces
workspaces, n = [], 0
for j in range(vsize):
    for i in range(hsize):
        workspaces.append([n, [x*i, y*j, ], ])
        n += 1
# Get the (1-indexed) viewport #
vp = list(i for i in workspaces if i[1] == ws)[0][0] + 1

# Get the current named viewports
vps = eval(getoutput(("gsettings", "get", SCHEMA, "viewports")));
names = eval(getoutput(("gsettings", "get", SCHEMA, "names")));

if vp not in vps:
  # If this viewport is not yet named, then just append it.
  vps.append(vp)
  names.append(name)
  getoutput(("gsettings", "set", SCHEMA, "viewports", listIntOutput(vps)));
  getoutput(("gsettings", "set", SCHEMA, "names", listStrOutput(names)));
else:
  # Rename the viewport.
  index = vps.index(vp)
  names[index] = name
  getoutput(("gsettings", "set", SCHEMA, "names", listStrOutput(names)));

Based off of this script: http://askubuntu.com/a/17492/284331

The one caveat I ran into is that

gconftool --get /apps/compiz-1/general/screen0/options/hsize # and vsize

didn't return the right values that I had set in ccsm, so I had to manually set them separately in order for the script to work.

gconftool --set /apps/compiz-1/general/screen0/options/hsize #
gconftool --set /apps/compiz-1/general/screen0/options/vsize #
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.