I am trying to combine applescript with bash script but its not working for some reason. Can someone correct my syntax error please? (when executing its saying line 18: syntax error: unexpected end of file there is no line 18??)
2 #!/bin/sh
3 declare -a sites
4 sites=("www.google.com")
5 for site in "${sites[@]}"; do
6 if ! wget "$site" --timeout 1 -O - 2> /dev/null | grep "server down" then
7 echo "The site is down"
8
9 osascript <<EOF
10 tell application "Google Chrome" to tell the tab of its window
11 reload
12 end tell
13 EOF
14
15
16 fi
17 done
So the aim is to look for a site, grep a specific message if true reload google chrome.
UPDATE: So I manage to get it to implement the appscript with a function but its keep spiting out echo connected even if the site is down. This is updated code:
2 #!/bin/sh
3
4 function ex_app_scpt () {
5 `osascript <<-AppleScript
6 tell application "Google Chrome" to tell the tab of its window
7 reload
8 end tell
9 return quit
10 AppleScript`
11 }
12
13 declare -a sites
14
15
16 if [ /usr/bin/wget "www.google.com" --timeout 1 -O - 2> /dev/null | grep "server down" ]; then
17 echo "The site is down"
18 ex_app_scpt
19 else
20 echo "connected"
21 fi
Any reason why?
then