Is there a way to reload a Google Chrome tab in Ubuntu using just the terminal. I don\'t want to just open a new window, but to actually refresh a tab!
Extra que
Important note: a probably better answer has been posted after this one, please also see that answer, based on the Chromix-Too tool, and use the one you prefer for your use case.
This answer starts from the solution kindly provided by blackloop, but it can work with multiple windows and let you select the right tab in the right window, by using string comparison for tab titles and by using the capability of some browsers to select a specific tab by sending keystrokes.
The code has two parameters: the tab position in the window (a number from 1 to 8) and a substring of the tab title, to identify the correct tab.
The code below is based on Google Chrome, see comment on some code lines to learn how to change it for the Firefox case (or you can modify it to take the browser name in input).
Save this code in a file, say for example tab_refresh.sh
(Note: this code extends this code as in the answer by blockloop)
#!/bin/bash
BROWSER=google-chrome # Or BROWSER=firefox for the Firefox case
TABNUM=$1
TABTITLE=$2
CUR_WID=$(xdotool getwindowfocus)
for WID in $(xdotool search --onlyvisible --class $BROWSER)
do
xdotool windowactivate $WID
xdotool key "ctrl+$TABNUM"
# Or "alt+$TABNUM" for the Firefox case
WIN_TITLE=$(xdotool getwindowname $WID)
if [[ $WIN_TITLE = *"$TABTITLE"* ]]
then
xdotool key 'F5'
fi
done
xdotool windowactivate $CUR_WID
After creating the file, make it executable, for example by typing:
chmod +x tab_refresh.sh
Finally, to use this script, you have to type something like:
./tab_refresh.sh TABNUM TABTITLE
For example, say you want to update the 4th tab in a Google Chrome window where its 4th tab title contains the string foo
.
./tab_refresh.sh 4 foo