Я нашел способ запуска настроенного VPN с AppleScript здесь:
https://superuser.com/questions/358513/start-configured-vpn-from-command-line-osx
это моя модификация кода:
tell application "System Events"
tell current location of network preferences
try
set VPN to service "MyVPN" -- your VPN name here
on error
return "NOT A CORRECT VPN FOUND ON THIS COMPUTER"
end try
if exists VPN then
connect VPN
end if
delay 15
if current configuration of VPN is connected then
return "OK"
else
return "CONNECTION ERROR"
end if
end tell
Если вы хотите, вы можете запустить этот скрипт внутри вашего проекта COCOA следующим образом:
Получение возвращаемого значения AppleScript в Obj-C
NSString* path = [[NSBundle mainBundle] pathForResource:@"VPNCONNECTION" ofType:@"scpt"];
NSURL* url = [NSURL fileURLWithPath:path];
NSDictionary* errors = [NSDictionary dictionary];
NSAppleScript* appleScript = [[NSAppleScript alloc] initWithContentsOfURL:url error:&errors];
NSAppleEventDescriptor *result = [appleScript executeAndReturnError:&errors];
NSLog(@"result = %@",result);
Вы не можете найти мой вопрос здесь:
Objective-C запускает VPN-соединение