开发者

Firefox refresh current tab from command-line

I'd like to trigger a tab refresh on Firefox from a command line. I'm working on a web app and the refresh goes after the app compiles. I trigger the compile from a command in my IDE. It's not a fixed url, nor can it be derived from the open file in the IDE. Thus, the currently open url in the active tab.

The thing is, I'm in a double headed box with no Xinerama support, which means I can't alt+tab to Firefox, instead I must move the mouse to the other screen, click on Firefox and then Ctrl+R. That can't be right.

I tried some sort 开发者_JAVA百科of bookmarklet stuff, like DISPLAY=':0.1' firefox -remote 'openurl(javascript:alert(1);)' , but FF wouldn't run that.

Any ideas?


You can use xdotool for automation. Install on Ubuntu with

sudo aptitude install xdotool

Then you can search for windows and send keys or mouse events, see man xdotool for the full documentation. I use following script on Ubuntu 16.04 LTS during development:

WID=`xdotool search --name "Mozilla Firefox" | head -1`
xdotool windowactivate $WID
xdotool key F5

Note: in the older versions, e.g. Ubuntu 14.04 the flag is --title instead of --name.

See also the xdotool project site.


Here's an updated version of @geekQ's script that will return focus to the previous program (however, the firefox window will still be pulled to the top).

#!/bin/bash

CURRENT_WID=$(xdotool getwindowfocus)

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

xdotool windowactivate $CURRENT_WID


For OS X you can do it with these few lines of applescript:

activate application "Firefox"
tell application "System Events" to keystroke "r" using command down


With the --window option from the man-page it's actually a one-liner and quicker:

#!/bin/bash

xdotool key --window $(xdotool search --name "Mozilla Firefox") F5

edit:

..and even better using inotify to watch for file changes:

# 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


There is a nifty tool named IMACROS from IOPUS. You can write macros for the browser, then call the macros from a script.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜