-
-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathreload-browser.sh
executable file
·38 lines (30 loc) · 948 Bytes
/
reload-browser.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh
#
# Reloads the active tab of the given browser (defaults to Chrome).
# Keeps the browser window in the background (Chrome/Safari only).
# Can optionally execute a given command before reloading the browser tab.
# Browser reloading is supported on MacOS only for now.
#
# Usage: ./reload-browser.sh [chrome|safari|firefox] -- [command args...]
#
set -e
RELOAD_CHROME='tell application "Google Chrome"
reload active tab of window 1
end tell'
RELOAD_SAFARI='tell application "Safari"
set URL of document 1 to (URL of document 1)
end tell'
RELOAD_FIREFOX='activate application "Firefox"
tell application "System Events" to keystroke "r" using command down'
case "$1" in
firefox) OSASCRIPT=$RELOAD_FIREFOX;;
safari) OSASCRIPT=$RELOAD_SAFARI;;
*) OSASCRIPT=$RELOAD_CHROME;;
esac
if shift; then
[ "$1" = "--" ] && shift
"$@"
fi
if command -v osascript > /dev/null 2>&1; then
exec osascript -e "$OSASCRIPT"
fi