【问题标题】:Applescript to mount network drives no longer working on 10.8.4Applescript 挂载网络驱动器不再适用于 10.8.4
【发布时间】:2013-10-15 12:27:41
【问题描述】:
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

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

【问题讨论】:

    标签: macos applescript osx-mountain-lion


    【解决方案1】:

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

    此外,“mount volume”命令是一个 applescript 命令...不是 Finder 或 System Events 命令。因此,它不应该出现在任何代码块中。

    所以你有几个问题。我真的很惊讶您的代码在以前版本的 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
    

    【讨论】:

    • 完美!像魅力一样工作,谢谢 Regulus!
    • 很高兴它有效。请在这个答案旁边打勾,让大家知道你找到了答案。祝你好运。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多