Skip to content

Instantly share code, notes, and snippets.

@rbeer
Created January 6, 2017 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbeer/eaca5df454d9bafa1bd0bbb517c3fe4b to your computer and use it in GitHub Desktop.
Save rbeer/eaca5df454d9bafa1bd0bbb517c3fe4b to your computer and use it in GitHub Desktop.
chrome-tab-doctor
#!/usr/bin/env bash
# exit codes:
# - 0: ok
# - 1: unknown (fatal)
# - 2: no window found (fatal)
# $1 = key (sequence) to send
# allows + operand for concatenation, e.g. ctrl+e, alt+h
# use space for separation, e.g. "f o o"
function send_keys_to_window() {
xdotool windowactivate --sync $BROWSER_WINDOW_ID key $1
echo $?
}
# $1 = window name (a/k/a title) regex
function refresh_window() {
send_keys_to_window "F5"
}
# $1 = url to navigate to
function open_url_in_same_tab() {
send_keys_to_window "alt+d ctrl+a $1"
}
BROWSER_WINDOW_NAME_REGEX="(doc).*Chrom(e|ium)$"
echo "Looking for window with --name \"$BROWSER_WINDOW_NAME_REGEX\" ..."
BROWSER_WINDOW_ID=`xdotool search --name $BROWSER_WINDOW_NAME_REGEX`
if [ -z "$BROWSER_WINDOW_ID" ]; then
echo "Nothing found! Exiting. (code=2)"
exit 2
else
echo "Matching window with ID: $BROWSER_WINDOW_ID"
fi
res=$(refresh_window)
[ "$res" -eq 0 ] && echo "window refreshed"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment