AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 17484
Accepted
wajiw
wajiw
Asked: 2010-12-15 16:12:02 +0800 CST2010-12-15 16:12:02 +0800 CST 2010-12-15 16:12:02 +0800 CST

有没有办法从命令行检测您当前所在的工作区?

  • 772

我试图弄清楚如何从 gnome 中的终端脚本获取工作区编号。有任何想法吗?

gnome command-line workspaces
  • 5 5 个回答
  • 5724 Views

5 个回答

  • Voted
  1. Best Answer
    Isaiah
    2010-12-15T16:35:33+08:002010-12-15T16:35:33+08:00

    如果您不使用 Compiz,则可以使用xdotool 安装 xdotool。

    例子:

    xdotool get_desktop
    

    0如果从第一个工作区1运行,如果从第二个等运行,这将返回。

    • 17
  2. mrtimdog
    2013-06-13T22:58:57+08:002013-06-13T22:58:57+08:00

    一个旧的,已回答的线程,但我只是在寻找相同的信息。您可以使用标准 xorg 工具执行此操作:

    xprop -root -notype _NET_CURRENT_DESKTOP
    
    • 10
  3. Stefano Palazzo
    2010-12-15T17:16:00+08:002010-12-15T17:16:00+08:00

    如果您使用的是compiz,这将更加困难。

    编辑:现在无论有没有compiz都可以使用,最后......

    我写了一个“小”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 安装 xdotool才能在 compiz 被禁用的情况下工作。

    • 7
  4. Nyamiou The Galeanthrope
    2010-12-15T17:11:48+08:002010-12-15T17:11:48+08:00

    无需安装任何东西,如果你使用 metacity,你可以使用这个:

    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
    
    • 3
  5. nealmcb
    2013-08-19T09:00:53+08:002013-08-19T09:00:53+08:00

    似乎使用 Unity,接受的答案

     xdotool get_desktop_viewport
    

    不起作用 - 它总是返回 0。我猜屏幕被配置为一个非常大的视口,其中只有一部分是可见的。另一种方法有点棘手,因为您必须知道工作空间的大小。IE:

     xdotool get_desktop_viewport
    

    如果您在右上角的工作区中,将返回类似“1600 0”的内容。第一个数字可能是您拥有的最大显示器的宽度。

    • 0

相关问题

  • 如何从命令行判断机器是否需要重新启动?

  • 是否有适用于 IMAP 邮件帐户的 Gnome 小程序?

  • 文件权限如何工作?文件权限用户和组

  • 如何在 Vim 中启用全彩支持?

  • 如果顶部面板中缺少会话小程序,如何注销?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何安装 .run 文件?

    • 7 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    如何获得 CPU 温度?

    • 21 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Marko Smith

    如何使用命令行将用户添加为新的 sudoer?

    • 7 个回答
  • Marko Smith

    更改文件夹权限和所有权

    • 9 个回答
  • Marko Smith

    你如何重新启动Apache?

    • 13 个回答
  • Marko Smith

    如何卸载软件?

    • 11 个回答
  • Marko Smith

    如何删除 PPA?

    • 26 个回答
  • Martin Hope
    NES 如何启用或禁用服务? 2010-12-30 13:03:32 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    Olivier Lalonde 如何在结束 ssh 会话后保持进程运行? 2010-10-22 04:09:13 +0800 CST
  • Martin Hope
    David B 如何使用命令行将用户添加为新的 sudoer? 2010-10-16 04:02:45 +0800 CST
  • Martin Hope
    Hans 如何删除旧内核版本以清理启动菜单? 2010-08-21 19:37:01 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve