在 Mac OS X 10.11 中,使用命令行打开 VPN 连接窗口时出现错误

2024-01-01

在 Mac OS X

function go-vpn {
/usr/bin/env osascript <<-EOF
tell application "System Events"
        tell current location of network preferences
                set VPN to service "LF VPN"
                if exists VPN then connect VPN
                repeat while (current configuration of VPN is not connected)
                    delay 1
                end repeat
        end tell
end tell
EOF
}

这将打开连接窗口(与从 VPN 下拉列表中选择“LF VPN”网络相同)。然而,在 El Capitan 中,我收到以下错误:

execution error: System Events got an error: Can’t get current configuration of service id "18E8C59B-C186-4669-9F8F-FA67D7AA6E53" of network preferences. (-1728)

如何在 El Capitan 中执行相当于此操作的操作,以及如何对其进行调试?


我在用着scutil相反,它在 OS X 10.11 上完美运行

set vpn_name to "'VPN Connection Name'"
set user_name to "my_user_name"
set otp_token to "XYZXYZABCABC"

tell application "System Events"
    set rc to do shell script "scutil --nc status " & vpn_name
    if rc starts with "Connected" then
        do shell script "scutil --nc stop " & vpn_name
    else
        set PWScript to "security find-generic-password -D \"802.1X Password\" -w -a " & user_name
        set passwd to do shell script PWScript
        -- installed through "brew install oath-toolkit"
        set OTPScript to "/usr/local/bin/oathtool --totp --base32 " & otp_token
        set otp to do shell script OTPScript
        do shell script "scutil --nc start " & vpn_name & " --user " & user_name
        delay 2
        keystroke passwd
        keystroke otp
        keystroke return
    end if
end tell
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Mac OS X 10.11 中,使用命令行打开 VPN 连接窗口时出现错误 的相关文章

随机推荐