답변:
당신 이 compiz 를 사용하는 경우 , 이것은 조금 더 어려울 것입니다.
편집 : 이것은 이제 compiz의 유무에 관계없이 작동합니다. 마지막으로 ...
"작은"파이썬 스크립트를 작성했습니다 :
#!/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 |
+---+---+
아무것도 설치하지 않고 메타 시티를 사용하는 경우 다음을 사용할 수 있습니다.
python -c "import wnck; s=wnck.screen_get_default(); s.force_update(); w=s.get_active_workspace(); w_num=w.get_number(); print(w_num);" 2>/dev/null