苹果脚本 Else/If
Apple Script Else/If
我目前正在尝试让驱动器在连接到我的网络时自动安装。唯一的问题是,当我未连接到网络时会显示错误,而连接到网络时则不会显示任何错误。我将如何禁用它?
这是我当前的脚本:
tell application "Finder"
mount volume "smb://(IP)/(Drive)" as user name "(user)"
end tell
这是一个用于检查网络连接的简单处理程序。它适用于以太网和 WiFi 连接。
如有必要,请调整前两行中的值。
property primaryEthernetDevice : "en0"
property primaryWiFiDevice : "en2"
property myIPAddress : "192.168.1.10"
property mySSID : "mySSID"
set {isConnected, IPAddress, ssid} to checkConnection()
if isConnected and ssid is mySSID then
mount volume "smb://(IP)/(Drive)" as user name "(user)"
end if
on checkConnection()
set wiredIP to do shell script "/sbin/ifconfig " & primaryEthernetDevice & " | /usr/bin/awk '/inet / {print }'"
if wiredIP is not "" then return {true, wiredIP, ""}
set wirelessIP to do shell script "/sbin/ifconfig " & primaryWiFiDevice & " | /usr/bin/awk '/inet / {print }'"
if wirelessIP is not "" then
set ssid to do shell script "/usr/sbin/networksetup -getairportnetwork " & primaryWiFiDevice & " | sed 's/Current Wi-Fi Network: //g'"
return {true, wirelessIP, ssid}
else
return {false, "", ""}
end if
end checkConnection
我目前正在尝试让驱动器在连接到我的网络时自动安装。唯一的问题是,当我未连接到网络时会显示错误,而连接到网络时则不会显示任何错误。我将如何禁用它?
这是我当前的脚本:
tell application "Finder"
mount volume "smb://(IP)/(Drive)" as user name "(user)"
end tell
这是一个用于检查网络连接的简单处理程序。它适用于以太网和 WiFi 连接。
如有必要,请调整前两行中的值。
property primaryEthernetDevice : "en0"
property primaryWiFiDevice : "en2"
property myIPAddress : "192.168.1.10"
property mySSID : "mySSID"
set {isConnected, IPAddress, ssid} to checkConnection()
if isConnected and ssid is mySSID then
mount volume "smb://(IP)/(Drive)" as user name "(user)"
end if
on checkConnection()
set wiredIP to do shell script "/sbin/ifconfig " & primaryEthernetDevice & " | /usr/bin/awk '/inet / {print }'"
if wiredIP is not "" then return {true, wiredIP, ""}
set wirelessIP to do shell script "/sbin/ifconfig " & primaryWiFiDevice & " | /usr/bin/awk '/inet / {print }'"
if wirelessIP is not "" then
set ssid to do shell script "/usr/sbin/networksetup -getairportnetwork " & primaryWiFiDevice & " | sed 's/Current Wi-Fi Network: //g'"
return {true, wirelessIP, ssid}
else
return {false, "", ""}
end if
end checkConnection