현재 명령 행에서 현재 작업 공간을 감지하는 방법이 있습니까?


12

그놈의 터미널 스크립트에서 작업 공간 번호를 얻는 방법을 알아 내려고합니다. 어떤 아이디어?

답변:


13

Compiz를 사용하지 않는 경우 xdotool 을 사용할 수 있습니다 xdotool 설치.

예:

xdotool get_desktop

0첫 번째 작업 공간에서 1실행하면 두 번째 등에서 실행 되면 반환 됩니다 .


7

오래되고 응답 된 스레드이지만 방금 동일한 정보를 얻었습니다. 표준 xorg 도구를 사용하여 다음을 수행 할 수 있습니다.

xprop -root -notype _NET_CURRENT_DESKTOP

6

당신 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 |
+---+---+

compiz가 비활성화 된 경우이 기능 을 사용하려면 xdotool 을 설치 해야xdotool 설치 합니다.


감사. cciz General Options가 내 데스크탑 크기 / 수직 가상 크기가 2.
nealmcb

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

0

Unity에서 허용되는 답변은

 xdotool get_desktop_viewport

작동하지 않습니다-항상 0을 반환합니다. 화면이 부분 만 보이는 큰 뷰포트로 구성되어 있다고 생각합니다. 작업 공간의 크기를 알아야하기 때문에 대안은 약간 까다 롭습니다. 즉 :

 xdotool get_desktop_viewport

오른쪽 상단 작업 공간에 있으면 "1600 0"과 같은 것을 반환합니다. 첫 번째 숫자는 아마도 가장 큰 디스플레이의 너비 일 것입니다.

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.