Если вы используете compiz, это будет немного сложнее.
edit: теперь это работает как с компилятором, так и без него, наконец ...
Я написал " маленький "скрипт python для этого:
#!/usr/bin/python
from subprocess import Popen, PIPE
getoutput = lambda x: Popen(x, stdout=PIPE).communicate()[0]
compiz_running = list(i for i in getoutput(("ps", "-aef", )).split("\n")
if "compiz --replace" in i and not "grep" in i) != []
if compiz_running:
# 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/general/screen0/options/hsize", )))
vsize = int(getoutput(("gconftool",
"--get", "/apps/compiz/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
print list(i for i in workspaces if i[1] == ws)[0][0]
# if compiz is not running
else: # this code via @DoR
print getoutput(("xdotool", "get_desktop", )).strip()
Сохраните это где-нибудь и отметьте его как исполняемый файл. Это будет выводить только число между 0 и количеством рабочих пространств.
Вот как выглядит перечисление:
+---+---+
| 0 | 1 |
+---+---+
| 2 | 3 |
+---+---+
Вы должны установить xdotool для этого, чтобы работать, если компилятор отключен.