anything-scripts

Disposable scripts to fix day to day problems.
git clone git://soucy.cc/anything-scripts.git
Log | Files | Refs

reload-browser (956B)


      1 #!/bin/sh
      2 # reload-browser - A cross-platform wrapper for reloading the current
      3 # browser tab
      4 # Eric Radman, 2014
      5 # http://eradman.com/entrproject/scripts/
      6 
      7 usage() {
      8 	case `uname` in
      9 	Darwin)
     10 		# applescript needs the exact title
     11 		echo "Usage: $(basename $0) Firefox [Safari \"Google Chrome\" ...]"
     12 		;;
     13 	*)
     14 		# xdotool uses regular expressions
     15 		echo "Usage: $(basename $0) Firefox [Chrome ...]"
     16 		;;
     17 	esac
     18 	exit 1
     19 }
     20 [ $# -lt 1 ] && usage
     21 
     22 for app in "$@"
     23 do
     24 	case `uname` in
     25 	Darwin)
     26 		/usr/bin/osascript <<-APPLESCRIPT
     27 		set prev to (path to frontmost application as text)
     28 		tell application "$app"
     29 		    activate
     30 		end tell
     31 		delay 0.5
     32 		tell application "System Events" to keystroke "r" using {command down}
     33 		delay 0.5
     34 		activate application prev
     35 		APPLESCRIPT
     36 		;;
     37 	*)
     38 		xdotool search --onlyvisible --class "$app" windowfocus key \
     39 		    --window %@ 'ctrl+r' || {
     40 			1>&2 echo "unable to signal an application named \"$app\""
     41 		}
     42 		;;
     43 	esac
     44 done