【问题标题】:Error: Can't open display: (null) Failed creating new xdo instance on mac OS错误:无法打开显示:(空)无法在 Mac OS 上创建新的 xdo 实例
【发布时间】:2018-09-12 19:26:28
【问题描述】:

我在互联网上查看了很多答案,但没有任何解决方案有帮助。 当我只是做open http://google.com 它工作时,我的默认浏览器是谷歌浏览器。我通过 brew 下载了 xdotool 包 我想要做的是,打开网页(任何网页)并每 10 秒刷新一次,我有以下代码:

#!/bin/bash
while true;
do
    export DISPLAY=:0.0
    export XAUTHORITY=/home/dogaister/.Xauthority
    open  http://google.com
    xdotool key command+r
    sleep 10
done

我也试过DISPLAY=':0'DISPLAY=':0.0',它们也没有用。

【问题讨论】:

  • Err... 你找错树了。 Mac 不使用 X11DISPLAYxdotool - macOS 甚至不附带 X11 服务器。您需要使用 Applescript。
  • @MarkSetchell 我在下载xdotool 之前遇到了一个错误,但是在我下载它之后并没有抛出那个错误。任何解决方案或起点?我以前从未写过Applescript
  • 尝试将其粘贴到终端中以了解情况...osascript -e 'tell application "Google Chrome" to tell the active tab of its first window to reload'
  • @MarkSetchell 我刚刚找到了相同的答案,如何指定标签号?我想每 10 秒刷新一次标签号 12,这只刷新一次,使用 repeat 会导致不下载页面
  • 删除原始脚本中的所有内容,从 export DISPLAYxdotool 并粘贴到我给你的部分。

标签: bash shell xdotool


【解决方案1】:
#!/bin/bash
while true;
do
    osascript -e 'tell application "Google Chrome" to reload (tabs of window 1 whose URL contains "google.ca")'
    sleep 10
    echo "Reloaded"
done

工作。感谢 Mark Setchell 的贡献

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-20
    • 1970-01-01
    相关资源
    最近更新 更多