Skip to content

Commit a721023

Browse files
committed
Execute a given command before reload.
Exit gracefully on platforms without AppleScript support.
1 parent 546e68f commit a721023

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

bin/macos-reload-browser.sh bin/reload-browser.sh

+13-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
#
44
# Reloads the active tab of the given browser (defaults to Chrome).
55
# Keeps the browser window in the background (Chrome/Safari only).
6+
# Can optionally execute a given command before reloading the browser tab.
7+
# Browser reloading is supported on MacOS only for now.
68
#
7-
# Usage: ./macos-reload-browser.sh [chrome|safari|firefox]
9+
# Usage: ./reload-browser.sh [chrome|safari|firefox] -- [command args...]
810
#
911

12+
set -e
13+
1014
RELOAD_CHROME='tell application "Google Chrome"
1115
reload active tab of window 1
1216
end tell'
@@ -24,4 +28,11 @@ case "$1" in
2428
*) OSASCRIPT=$RELOAD_CHROME;;
2529
esac
2630

27-
exec osascript -e "$OSASCRIPT"
31+
if shift; then
32+
[ "$1" = "--" ] && shift
33+
"$@"
34+
fi
35+
36+
if command -v osascript > /dev/null 2>&1; then
37+
exec osascript -e "$OSASCRIPT"
38+
fi

0 commit comments

Comments
 (0)