我并不经常使用 AppleScript,但我编写了一个简短的脚本来根据我是否在家或外出来安装网络驱动器:
set SSID to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk '/ SSID: / {print $2}'"
if SSID is "MyHomeSSID" then
mount volume "afp://my_local_home_server_address.local"
else if mount volume "afp://address_to_my_home_server:port" then
end if
当我运行它时,它会显示一个窗口,允许我选择要挂载的卷,但随后出现以下错误:
error "Can’t make file \"Drive:\" into type boolean." number -1700 from file "Drive:" to boolean
我不知道如何让它工作而不出现错误。
答案1
这是您收到的错误:
error "Can’t make file \"Drive:\" into type boolean." number -1700 from file "Drive:" to boolean
罪魁祸首是:
else if mount volume "afp://address_to_my_home_server:port" then
你知道为什么吗?[提示:boolean
值为true
和false
]
您需要重构控制语句的后半部分,if...then...else
如下所示:
if SSID is "MyHomeSSID" then
mount volume "afp://my_local_home_server_address.local"
else
mount volume "afp://address_to_my_home_server:port"
end if