Skip to content

Instantly share code, notes, and snippets.

@soulim
Created February 28, 2021 06:04
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 soulim/244fe3253e675e8db18280cd017d949e to your computer and use it in GitHub Desktop.
Save soulim/244fe3253e675e8db18280cd017d949e to your computer and use it in GitHub Desktop.
A cross-platform wrapper for reloading the current
#!/bin/sh
# reload-browser - A cross-platform wrapper for reloading the current
# browser tab
# Eric Radman, 2014
# http://eradman.com/entrproject/scripts/
usage() {
case `uname` in
Darwin)
# applescript needs the exact title
echo "Usage: $(basename $0) Firefox [Safari \"Google Chrome\" ...]"
;;
*)
# xdotool uses regular expressions
echo "Usage: $(basename $0) Firefox [Chrome ...]"
;;
esac
exit 1
}
[ $# -lt 1 ] && usage
for app in "$@"
do
case `uname` in
Darwin)
/usr/bin/osascript <<-APPLESCRIPT
set prev to (path to frontmost application as text)
tell application "$app"
activate
end tell
delay 0.5
tell application "System Events" to keystroke "r" using {command down}
delay 0.5
activate application prev
APPLESCRIPT
;;
*)
cw=$(xdotool getwindowfocus -f)
xdotool search --onlyvisible --class "$app" windowfocus key \
--delay 100 --window %@ 'ctrl+r' || {
1>&2 echo "unable to signal an application named \"$app\""
}
sleep 0.5
xdotool windowfocus $cw
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment