tell application "Finder"
tell current location of network preferences
set VPNservice to service "Company VPN" -- name of the VPN service
set isConnected to connected of current configuration of VPNservice
if isConnected then
-- the user_name field will show as blank
set user_name to ""
repeat while user_name = ""
set user_name to text returned of (display dialog "Please enter your user name:" default answer user_name)
end repeat
-- the pass_word field will show as blank
set pass_word to ""
repeat while pass_word = ""
set pass_word to text returned of (display dialog "Please enter your password:" default answer pass_word with hidden answer)
end repeat
--Mount network drives using entered credentials
try
mount volume "smb://user_name:pass_word@server/share"
mount volume "smb://user_name:pass_word@server/share"
end try
end if
end tell
end tell
我收到语法错误:预期的行尾但找到了属性。位置在第二行突出显示。为什么这不再起作用?
答案 0 :(得分:1)
系统事件了解网络首选项,而不是Finder。因此,在第一行中将“Finder”更改为“System Events”。
此外,“mount volume”命令是一个applescript命令...而不是Finder或System Events命令。因此,它不应该在任何tell代码块中。
所以你有几个问题。我真的很惊讶你的代码在MacOS X的早期版本中工作,因为这些不是10.8.4的新东西。以下是我编写代码的方法......
tell application "System Events"
tell current location of network preferences
set VPNservice to service "Company VPN" -- name of the VPN service
set isConnected to connected of current configuration of VPNservice
end tell
end tell
if isConnected then
-- the user_name field will show as blank
set user_name to ""
repeat while user_name = ""
set user_name to text returned of (display dialog "Please enter your user name:" default answer user_name)
end repeat
-- the pass_word field will show as blank
set pass_word to ""
repeat while pass_word = ""
set pass_word to text returned of (display dialog "Please enter your password:" default answer pass_word with hidden answer)
end repeat
--Mount network drives using entered credentials
try
mount volume "smb://user_name:pass_word@server/share"
mount volume "smb://user_name:pass_word@server/share"
end try
end if