Firefox从命令行刷新当前选项卡

rat*_*rat 19 shell firefox automation

我想从命令行触发Firefox上的选项卡刷新.我正在开发一个Web应用程序,并在应用程序编译后进行刷新.我从IDE中的命令触发编译.它不是固定的URL,也不能从IDE中的打开文件派生.因此,活动选项卡中的当前打开的URL.

问题是,我是一个没有Xinerama支持的双头盒子,这意味着我无法使用alt + tab到Firefox,而是我必须将鼠标移动到另一个屏幕,点击Firefox然后按Ctrl + R. 这不可能是正确的.

我尝试了某种书签类似的东西DISPLAY=':0.1' firefox -remote 'openurl(javascript:alert(1);)',但FF不会运行它.

有任何想法吗?

gee*_*ekQ 24

您可以使用xdotool进行自动化.在Ubuntu上安装

sudo aptitude install xdotool
Run Code Online (Sandbox Code Playgroud)

然后,您可以搜索窗口并发送键或鼠标事件,请参阅man xdotool完整文档.我在开发期间在Ubuntu 16.04 LTS上使用以下脚本:

WID=`xdotool search --name "Mozilla Firefox" | head -1`
xdotool windowactivate $WID
xdotool key F5
Run Code Online (Sandbox Code Playgroud)

注意:在旧版本中,例如Ubuntu 14.04,标志--title代替--name.

另请参阅xdotool项目站点我的完整博客文章.

  • 虽然它有切换到firefox窗口的不良副作用,但仍有效 (4认同)

Jas*_*son 11

这是 @geekQ 脚本的更新版本,它将把焦点返回到之前的程序(但是,firefox 窗口仍然会被拉到顶部)。

#!/bin/bash

CURRENT_WID=$(xdotool getwindowfocus)

WID=$(xdotool search --name "Mozilla Firefox")
xdotool windowactivate $WID
xdotool key F5

xdotool windowactivate $CURRENT_WID
Run Code Online (Sandbox Code Playgroud)


Chr*_*ian 6

我正在寻找相同的东西,但没有找到任何东西.但我现在使用的是一个Firefox插件,可以在更改配置的本地文件时重新加载页面.它被命名为Auto Reload.

  • 不幸的是,最近的更新中断了它。 (2认同)

ete*_*ame 6

使用--window手册页中的选项,它实际上是一句话并且更快:

#!/bin/bash

xdotool key --window $(xdotool search --name "Mozilla Firefox") F5
Run Code Online (Sandbox Code Playgroud)

编辑:

..甚至更好地使用 inotify来监视文件更改:

# refresher - send an F5 to a selected window on file change events
#!/bin/bash

project_root=$(pwd)
excluded=".*\.(swp|log|.*~)"
wid=$(xdotool selectwindow)
# ..waiting for user to select browser window..

while inotifywait --quiet --event modify --recursive --exclude "$excluded" $project_root
do
  xdotool key --window $wid F5
done
Run Code Online (Sandbox Code Playgroud)