尝试 运行 xdotool 但得到“无法打开显示:(空)”

Trying to to run xdotool but getting 'Can't open display: (null)'

很抱歉再次报告这个众所周知的错误消息。

对我来说没有任何用处。我正在 运行宁 MacOS Catalina,如果它很重要的话。

我在 Mac 上安装了 xdotoolbrew 并尝试 运行

xdotool getmouselocation

后面的错误信息是

Error: Can't open display: (null)
Failed creating new xdo instance

我一直在寻找解决方案,找到了很多答案。 运行 export DISPLAY=:0 一切都很好。但这对我不起作用。

PS:为了更好地理解:DISPLAY 到底是什么意思?是我电脑的显示器吗?

根据official notice by apple

X11 is no longer included with Mac, but X11 server and client libraries are available from the XQuartz project.

为什么 X11 在这种情况下很重要?

xdotool - 命令行 X11 自动化工具。

所以除了设置 export DISPLAY=:0

安装xquartz.

DISPLAY 到底是什么意思?

根据x manual

From the user's perspective, every X server has a display name of the form:

               hostname:displaynumber.screennumber

This information is used by the application to determine how it should connect to the server and which screen it should use by default (on displays with multiple monitors):

  1. hostname The hostname specifies the name of the machine to which the display is physically connected. If the hostname is not given, the most efficient way of communicating to a server on the same machine will be used.

  2. displaynumber The phrase "display" is usually used to refer to collection of monitors that share a common keyboard and pointer (mouse, tablet, etc.). Most workstations tend to only have one keyboard, and therefore, only one display. Larger, multi-user systems, however, frequently have several displays so that more than one person can be doing graphics work at once. To avoid confusion, each display on a machine is assigned a display number (beginning at 0) when the X server for that display is started. The display number must always be given in a display name.

  3. screennumber Some displays share a single keyboard and pointer among two or more monitors. Since each monitor has its own set of windows, each screen is assigned a screen number (beginning at 0) when the X server for that display is started. If the screen number is not given, screen 0 will be used.

找到了更简单的描述here

显示包括(简化):

  • 一个键盘
  • 一只老鼠
  • 一个屏幕

即当您通过 ssh 连接时,您使用的是这 3 个的不同集合。