使用 xdotool 自动刷新网页 - 在窗口焦点后不发送密钥 [英] Automatic web-page refresh using xdotool - not sending key after window focus

查看:62
本文介绍了使用 xdotool 自动刷新网页 - 在窗口焦点后不发送密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定:

我在我的 Ubuntu 计算机上打开了带有 [Firefox 页面标题] 页面的 Firefox.

I have Firefox with the [Firefox Page Title] page open on my Ubuntu computer.

这是我的命令:

xdotool search "[Firefox Page Title]" windowactivate --sync key --clearmodifiers ctrl+r

文档:

带有文档/示例的 xdotool 网站是这里.

xdotool website with documentation/examples is here.

直接来自 xdotool 网站的示例:

Example straight from the xdotool website:

# As of version 2.20100623, you can do this simpler version of above:
xdotool search "Mozilla Firefox" windowactivate --sync key --clearmodifiers ctrl+l

注意事项:

我使用的是 xdotool 版本 2.20110530.1.

I'm using xdotool version 2.20110530.1.

该命令正确地将我的屏幕聚焦到我选择的任何窗口标题,但它不会将 ctrl+r 键发送到窗口,因为网站不会刷新.我没有收到来自命令的错误消息.(Firefox 中的刷新快捷方式是 ctrl+r)

The command correctly focuses my screen to whatever window title I choose, but it doesn't send the ctrl+r key to the window, as the website doesn't refresh. I receive no error messages from the command. (Refresh shortcut in Firefox is ctrl+r)

想要的行为:

希望该命令(当它起作用时)应用于在我的服务器计算机上 24/7 打开的 Web 服务器统计页面,我希望它自动刷新页面,以便我可以查看我网站的新流量无需我做任何事情.

The command will hopefully (when it works) be applied to a web server statistics page that is open 24/7 on my server computer, I'd like it to refresh the page automatically so I can view new traffic to my website without me having to do anything.

我愿意使用可以提供此功能的其他应用程序,如果您知道其他简单/类似的东西,请提供它作为答案!如果我不能让这个工作,我会默认下一个最好的东西.

I'm open to using other applications that can provide this functionality, if you know of something else that's easy/similar, please provide it as an answer! If I can't get this working I'll default to the next best thing.

推荐答案

在尝试了几种不同的方法使 xdotool 正常工作后,我倾向于相信 xdotool 本身就是问题.这是我尝试过的,没有奏效.

After trying several different approaches to get xdotool to work correctly, I'm inclined to believe that xdotool itself is the issue. Here is what I tried, none worked.

  • 从终端运行命令(和变体 - 删除/添加参数).
  • 从 SH 脚本运行命令(和变体 - 删除/添加参数).
  • 在 F5 和 ctrl+r 键之间切换,因为它们都应该刷新 Firefox 页面.
  • 尝试其他参数,例如:
    • --window 设置密钥要发送到的窗口.
    • --delay 在发送密钥之前,在窗口聚焦之后添加延迟.
    • 在发送密钥之前,在窗口聚焦之后添加睡眠.

    我也在脚本中尝试过这些命令,正如 xdotool 的首页所推荐的那样,尽管它声明这是旧"版本,因为它被分成多个命令.新"版本是我之前尝试执行的版本,是一个命令(请参阅问题).

    I also tried these commands in a script, as the frontpage for xdotool recommends, although it states this is the "older" version, as it is separated into multiple commands. The "new" version was the version I was trying to execute before and is a single command (see question).

    WID=`xdotool search "Firefox Page Title"`
    xdotool windowactivate --sync $WID
    xdotool key --clearmodifiers ctrl+r
    

    上述所有尝试总是正确地聚焦到我想要的窗口,但无论是 F5 还是 ctrl+r,它都不会发送键.

    但是,以下工作正常:

    xdotool selectwindow key ctrl+r
    

    xdotool selectwindow key F5
    

    selectwindow 命令在执行时会将光标变成一个矩形选择工具,此时您可以选择要聚焦的窗口,在这种情况下,可以选择要发送的窗口ctrl+r 或 F5 键即可.不幸的是,这不是我想要的,因为它需要用户输入才能正常工作.

    The selectwindow command, when executed, turns your cursor into a rectangular selection tool at which point you can select the window you want to be focused and, in this case, what window to send either the ctrl+r or F5 key to. Unfortunately, this is not what I was looking for, as it requires user input to work correctly.

    最终解决方案:

    我的解决方案(因为我试图使用 xdotool 不断刷新网页)是使用 ReloadEvery Firefox 附加组件,它会在您选择的任何时间间隔内刷新您设置的任何页面.它旨在复制 Opera 浏览器的内置自动页面刷新功能,到目前为止,它效果很好.

    My solution (since I was attempting to use xdotool to constantly refresh a web-page) was to use the ReloadEvery Firefox add-on, which refreshes any page you set it on in any time interval you choose. It is intended to be a replica of the Opera browser's built-in automatic page refresh feature, and thus far, it works well.

    对于那些使用 Chrome 并正在寻找类似解决方案的人来说,还有很多附加组件可供您使用.https://chrome.google.com/webstore/search/auto%20refresh

    For those of you who use Chrome and are looking for a similar solution, there are plenty of add-ons available for you too. https://chrome.google.com/webstore/search/auto%20refresh

    这篇关于使用 xdotool 自动刷新网页 - 在窗口焦点后不发送密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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