get X11 window id of terminal from shell

送分小仙女□ 提交于 2019-12-10 18:44:33

问题


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

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.


回答1:


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?

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

ENVIRONMENT

   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:

  • https://unix.stackexchange.com/questions/3197/how-to-identify-which-xterm-a-shell-or-process-is-running-in

  • Get X window id from process in bash



来源:https://stackoverflow.com/questions/22250445/get-x11-window-id-of-terminal-from-shell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!