![](/img/trans.png)
[英]Having trouble with shell script result in applescript, in Automator
[英]Applescript, having trouble with if and subprocesses of this script
基本上,我寫了一個腳本,當vpn斷開連接時殺死網絡(到目前為止,wifi,現在會嘗試找出以太網)。 我想添加一個故障保護功能,該功能也會殺死應用程序,但是當我添加以下代碼時
if application "iTunes" is running then do shell script "killall iTunes"
if application "uTorrent" is running then do shell script "killall uTorrent"
if application "Transmission" is running then do shell script "killall Transmission"
if application "Safari" is running then do shell script "killall Safari"
if application "Google Chrome" is running then do shell script "killall 'Google Chrome'"
if application "Palringo" is running then do shell script "killall Palringo"
腳本,我一直無法運行它。 老實說,我不確定在這種情況下應該如何使用ifs。
我希望它執行以下操作
- if myConnection is not null and
- if vpn is not connected
- kill wifi
- and also do the following "if statements":
if application "iTunes" is running then do shell script "killall iTunes"
if application "uTorrent" is running then do shell script "killall uTorrent"
if application "Transmission" is running then do shell script "killall Transmission"
if application "Safari" is running then do shell script "killall Safari"
if application "Google Chrome" is running then do shell script "killall 'Google Chrome'"
if application "Palringo" is running then do shell script "killall Palringo"
但是我不確定如何做到這一點/我所做的一切都失敗了。 這是我的代碼。 *
on idle
tell application "System Events"
tell current location of network preferences
set myConnection to the service "BTGuard VPN"
if myConnection is not null then
if current configuration of myConnection is not connected then do shell script "/usr/sbin/networksetup -setairportpower en1 off"
if application "iTunes" is running then do shell script "killall iTunes"
if application "uTorrent" is running then do shell script "killall uTorrent"
if application "Transmission" is running then do shell script "killall Transmission"
if application "Safari" is running then do shell script "killall Safari"
if application "Google Chrome" is running then do shell script "killall 'Google Chrome'"
if application "Palringo" is running then do shell script "killall Palringo"
end if
end tell
return 0
end tell
end idle
那就是失敗的原因。 我嘗試的所有內容都有問題。 更正/指導/建議/幫助將不勝感激。
我將把“ do shell script”行移到“ system events”告訴代碼塊之外。 這樣的事情會起作用...
on idle
set vpnIsDisconnected to false
tell application "System Events"
tell current location of network preferences
set myConnection to the service "BTGuard VPN"
if myConnection is not null then
if current configuration of myConnection is not connected then set vpnIsDisconnected to true
end if
end tell
end tell
if vpnIsDisconnected then
do shell script "/usr/sbin/networksetup -setairportpower en1 off"
if application "iTunes" is running then do shell script "killall iTunes"
if application "uTorrent" is running then do shell script "killall uTorrent"
if application "Transmission" is running then do shell script "killall Transmission"
if application "Safari" is running then do shell script "killall Safari"
if application "Google Chrome" is running then do shell script "killall 'Google Chrome'"
if application "Palringo" is running then do shell script "killall Palringo"
end if
return 0
end idle
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.