Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox refresh current tab from command-line

Tags:

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 of bookmarklet stuff, like DISPLAY=':0.1' firefox -remote 'openurl(javascript:alert(1);)' , but FF wouldn't run that.

Any ideas?

like image 279
rat Avatar asked Apr 04 '11 22:04

rat


People also ask

How do I get Firefox to refresh tabs automatically?

You can enable the auto-refresh from Firefox Advanced Options by clicking the orange Firefox button on the top left corner of the browser and then clicking "Options." From the list of options, select "Advanced." Under the "General" tab, in the "Accessibility" section, you will be able to remove the check mark next to " ...

How do I force Firefox to refresh?

Firefox and Windows: To hard refresh on Firefox on Windows, there are also two easy hotkey commands you can use: Hold down Ctrl, Shift and the 'R' key. Or Hold down Ctrl and press F5.

How do you refresh a page in Linux?

Hold down Ctrl (Control) + Shift and click R. Or hold down Ctrl (Control) and click the Reload button. Or hold down Ctrl (Control) and click F5.

How do I reset Firefox from command line?

No mouse needed. firefox -safemode or -safe-mode then a new window should show to enter safe mode or Reset, hit the right keyboard key, and press enter on "Reset Firefox". No mouse needed.


2 Answers

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.

like image 180
geekQ Avatar answered Sep 28 '22 03:09

geekQ


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 
like image 24
Jason Axelson Avatar answered Sep 28 '22 02:09

Jason Axelson