从 shell 获取终端的 X11 窗口 ID [英] get X11 window id of terminal from shell

查看:40
本文介绍了从 shell 获取终端的 X11 窗口 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取运行我的 shell 脚本的终端的窗口 ID?

How can I get the window ID of the terminal that my shell script is running in?

背景:我需要编写一个脚本来根据它运行的虚拟桌面做一些事情.要获取虚拟桌面(不是当前桌面,我可能会在脚本运行时更改它),我需要终端的窗口 ID脚本正在运行.如果脚本不是从终端运行的,它应该会失败并显示错误.

Background: I need to write a script to do something based on which virtual desktop it is running in. To get the virtual desktop (not current desktop, I may change it while the script is running), I need the window ID of the terminal that the script is running in. If the script is not run from a terminal, it should fail with an error.

推荐答案

我对 X11 知之甚少,但在我的终端中运行 env 命令,我发现了一个环境变量 WINDOWID,它在同一终端的不同选项卡中显示相同的数字,但在另一个终端中显示不同的数字.也许这就是您所需要的?

I know very little of X11, but running the env command in my terminal, I spotted an environment variable WINDOWID, that shows the same number in different tabs of the same terminal, but a different number in another terminal. Perhaps that's what you need?

它似乎是一个 Xterm 的东西(可能是任何模仿 Xterm 行为的终端.xterm(1) 手册页只说:

It does appear to be an Xterm thing (and probably any terminal that mimicks Xterms behaviour. The xterm(1) man page only says:

环境

   Xterm sets several environment variables:
   ...
   WINDOWID
        is set to the X window id number of the xterm window.

其他一些可能相关的问题及其答案:

Some other possibly relevant questions with answers:

从进程中获取X窗口ID在 bash 中

这篇关于从 shell 获取终端的 X11 窗口 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆