0
我试图将applescript与bash脚本结合起来,但由于某种原因它不工作。有人可以纠正我的语法错误吗? (执行它说line 18: syntax error: unexpected end of file
时,有没有线18 ??)如何将苹果脚本与bash脚本结合使用
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
所以其目的是寻找一个网站,用grep特定的消息如果属实重装谷歌浏览器。
更新: 所以我设法让它实现一个功能的appscript,但它仍然吐出回声连接即使网站已关闭。这是更新代码:
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
任何原因为什么?
分号之前'then' –
失踪BTW,通过http://shellcheck.net/运行,这将可能已经没有卷入人类发现它。 –
如果我做'grep'服务器关闭';然后'它仍然错误'语法错误:文件的意外结束' – tranmaster