Last active
December 1, 2021 18:24
-
-
Save Eloi/4631945f8ca1350b1188ac762838cb14 to your computer and use it in GitHub Desktop.
Simple shellscript to easily reload browser/terminal/other windows, without losing focus on the current window. Bind it to some useful key shortcut (p.e. win+r) to speed up web development process ;)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ -n "$1" ]; then | |
if [ "$1" = "grab_id" ]; then | |
xdotool selectwindow >/tmp/autoreload_window_id | |
elif [ "$1" = "reload" ]; then | |
WINDOWID=`cat /tmp/autoreload_window_id` | |
WINDOWCLASS=`xprop -id $WINDOWID WM_CLASS` | |
WINDOWNAME=`xprop -id $WINDOWID WM_NAME` | |
CURRENTWIN=`xdotool getactivewindow` | |
# Switch reload action depending on window type | |
case "$WINDOWCLASS" in | |
*x-terminal-emulator*) | |
echo "Reload TERMINAL" | |
xdotool key --window $WINDOWID Up | |
xdotool key --window $WINDOWID Return | |
;; | |
*chromium*) | |
xdotool windowactivate $WINDOWID | |
case "$WINDOWNAME" in | |
*Postman*) | |
echo "Reload Postman / Does not work, WIP" | |
sleep 2; xdotool keydown ctrl key Return keyup ctrl | |
;; | |
*) | |
echo "Reload Chromium" | |
xdotool key --window $WINDOWID F5 | |
;; | |
esac | |
xdotool windowactivate $CURRENTWIN | |
;; | |
*) | |
echo "Reload Generic (browser)" | |
xdotool key --window $WINDOWID F5 | |
;; | |
esac | |
fi | |
else | |
echo "Help:" | |
echo "" | |
echo "browser_automation.sh grab_id -> Select and remember window to reload" | |
echo "browser_automation.sh reload -> Reload previously selected window" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment