Hi Everyone,
I am looking for an apple script which will fill all the VPN connection settings and then delete itself. I have looked around and found these two scripts.
This one will create a vpn connection but it will skip a field and then fills the rest of the spaces with wrong info and then it will give me error:
set vpnname to "My VPN"
set vpnserver to "MY server address"
set vpnsecret to "vpn secret"
set vpngroup to "vpn group"
tell application "System Events"
if not (UI elements enabled) then
tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.universalaccess"
display dialog "This script requires access for assistive devices be enabled." & return & return & "To continue, click the OK button and enter an administrative password in the security dialog." with icon note
end tell
set UI elements enabled to true
if UI elements enabled is false then return "User Cancelled"
delay 1
end if
tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.network"
display dialog "This script will now create the VPN connection." & return & return & "Please wait as the operation is in progress, and do not click anything. This should not take longer than 30 seconds. You will be notified when the process is complete." with icon caution
set vpnusername to display dialog "Please enter your username:" default answer "" with icon note
set vpnpassword to display dialog "Please enter your password:" default answer "" with icon note with hidden answer
end tell
tell application "System Events"
tell process "System Preferences"
tell window 1
click button 5
delay 1
end tell
tell sheet 1 of window 1
click pop up button 1
click menu item "VPN" of menu 1 of pop up button 1
delay 1
repeat until exists pop up button 2
delay 0.2
end repeat
click pop up button 2
--click menu item "L2TP over IPSEC" of menu 1 of pop up button 2
--click menu item "PPTP" of menu 1 of pop up button 2
click menu item "Cisco IPSec" of menu 1 of pop up button 2
set focused of text field 1 to true
keystroke "a" using command down
keystroke vpnname
click button 1
delay 1
end tell
tell group 1 of window 1
click checkbox 1
set focused of text field 1 to true
keystroke vpnserver
keystroke tab
keystroke text returned of vpnusername
click button 2
delay 1
end tell
tell sheet 1 of window 1
set focused of text field 3 to true
keystroke text returned of vpnpassword
keystroke tab
keystroke vpngroup
keystroke tab
keystroke vpnsecret
click button 2
delay 1
end tell
tell window 1
click button 1
delay 1
end tell
tell sheet 1 of window 1
click button 1
end tell
end tell
end tell
tell application "System Preferences"
quit saving yes
end tell
display alert "The VPN has been configured. Click on the \"Connect\" button to access the network." & return & return & "The connection status and various options are available through the menu bar at the top of the screen." as informational
end tell
Second script was found which creates a connection and it works every time without a problem:
set VPN to "MY VPN"
tell application "System Preferences"
reveal pane "Network"
activate
tell application "System Events"
tell process "System Preferences"
tell window 1
click button "Add Service"
tell sheet 1
click pop up button 1
click menu item "VPN" of menu 1 of pop up button 1
delay 1
click pop up button 2
click menu item "Cisco IPSec" of menu 1 of pop up button 2
keystroke tab
keystroke VPN
click button "Create"
end tell
click button "Apply"
end tell
end tell
delay 1 -- optional (just for visual feedback)
keystroke "w" using {command down}
end tell
end tell
First script worked for once and then it started giving me error and second one is very simple and works every time so far.
I still need any of those scripts to do these things:
- Create a VPN connection
- Fill-in all the connections settings (without username and password)
- once the connection is created and configured then script should delete itself.
Thanks,
Model: MacBook Pro (10.6.8)
AppleScript: 2.1.2
Browser: Firefox 8.0
Operating System: Mac OS X (10.6)