1
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

我收到一个语法错误:预期行尾,但找到了属性。位置在第二行突出显示。为什么这不再起作用?

4

1 回答 1

2

系统事件知道网络首选项,而不是 Finder。因此,将第一行中的“Finder”更改为“System Events”。

此外,“挂载卷”命令是一个 applescript 命令......不是 Finder 或系统事件命令。因此,它不应该在任何代码块中。

所以你有几个问题。我真的很惊讶您的代码在以前版本的 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
于 2013-10-08T15:59:35.367 回答