使用命令行打开VPN连接窗口会给我一个错误

使用命令行打开VPN连接窗口会给我一个错误

本文介绍了在Mac OS X 10.11中,使用命令行打开VPN连接窗口会给我一个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mac OS X< = 10.10上,我可以运行以下命令来打开VPN连接窗口:

On Mac OS X <= 10.10, I could run the following command to open a VPN connection window:

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中,出现以下错误:

This would open the connection window (same as selecting the "LF VPN" network from the VPN dropdown). In El Capitan, however, I get the following error:

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中做到这一点,以及如何对其进行调试?

How would one do the equivalent of this in El Capitan, and how can this be debugged?

推荐答案

我改用了scutil,它在OS X 10.11上也能正常工作

I'm using scutil instead, and it works flawlessly on 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

这篇关于在Mac OS X 10.11中,使用命令行打开VPN连接窗口会给我一个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 05:45