Mavericks (10.9) Assistive Devices - VPN Configuration Automation

Since OS X 10.9 has changed the way in which assistive devices are managed, it has caused a problem for our automated scripts to configure a VPN connection. There doesn’t appear to be a way of automatically enabling the checkbox for AppleScript Editor within Privacy > Accessibility (unless you can say otherwise). We have looked at involving the user to interact with the GUI as minimally as possible. Now whilst this appears to be a new security feature with 10.9 to prevent enabling the AppleScript Editor we would hope that it would be possible to uncheck the box through AppleScript as at that point it is enabled??? Given that we are producing a VPN connector for our users home Macs, we do not wish to leave the AppleScript Editor enabled. If anyone can advise on how to either set the value for the checkbox against AppleScript Editor in Privacy > Accessibility or indeed using GUI scripting to click the checkbox (to deselect) we’d be delighted to hear from you.

Our current script workings look something similar to the below:

Configure VPN:


set vpnname to "TEST"
set vpnserver to "vpn-test.com"
set vpnsecret to "123456"

display alert "Please note that you are about to configure a VPN connection." & return & return & "Please read and follow the on screen instructions carefully." as informational

tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.security" --get the name of every anchor of pane id "com.apple.preference.security"
reveal anchor "Privacy_Accessibility" of pane id "com.apple.preference.security"
set adminusername to display dialog "Please enter your Administrative username:" default answer "" with icon note
set adminpassword to display dialog "Please enter your Administrative password:" default answer "" with icon note with hidden answer
tell application "System Events"
tell process "System Preferences"
tell window 1
click button 1
end tell
end tell
end tell
--tell process system preferences
--if title of button 4 of window 1 is "Click the lock to make changes." 
--then set preferencesLocked to true
--click button "Click the lock to make changes."
--end if
end tell
display dialog "The process requires you to complete the following steps:" & return & "______________________________________________" & return & return & "1 - Unlock the padlock in the bottom left of the 'Security and Privacy' pane by clicking on it." & return & return & "2 - Provide your administrator username and password when requested and click 'Unlock'." & return & return & "3 - Now, place a check in the box next to AppleScript Editor." & return & return & "4 - When you have completed the above, click 'OK' on this box to complete the VPN setup." & return & "______________________________________________" & return & return & "(Please note that your Macs security will not be compromised as this change will be undone once the VPN is successfully configured)" & return & "______________________________________________" with icon note
if button returned of result = "OK" then
tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.network"
set vpnusername to display dialog "Please enter your University username:" default answer "" with icon note
set vpnpassword to display dialog "Please enter your University password:" default answer "" with icon note with hidden answer
display dialog "Please wait while the operation is in progress, and do not click anything after you have clicked 'OK' below." & return & return & "This should no take longer than 1 minute. You will be notified when the process is complete." with icon caution
end tell
tell application "System Events"
tell process "System Preferences"
tell window 1
click button 9
--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
--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
delay 1
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 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"
activate
set current pane to pane id "com.apple.preference.security"
--get the name of every anchor of pane id "com.apple.preference.security"
reveal anchor "Privacy_Accessibility" of pane id "com.apple.preference.security"
end tell
tell application "System Preferences"
quit saving yes
end tell
display alert "The configuration of your VPN connection has now been completed." & return & return & "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
else
tell application "System Preferences"
quit saving no
end tell
end if
--end tell

Disable AppleScript Editor in Privacy > Accessibility:


tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.security"
get the name of every anchor of pane id "com.apple.preference.security"
reveal anchor "Privacy_Accessibility" of pane id "com.apple.preference.security"
set adminusername to display dialog "Please enter your Mac Admin username:" default answer "" with icon note
set adminpassword to display dialog "Please enter your Mac Admin password:" default answer "" with icon note with hidden answer
tell application "System Events"
tell process "System Preferences"
tell window "Security & Privacy"
click button 4
delay 1
keystroke text returned of adminpassword
keystroke tab
keystroke text returned of adminusername
delay 1
keystroke return
--tell window "Allow the apps below to control your computer."
--click checkbox "AppleScript Editor" of sheet 1 of window 1
--click checkbox 2
--end tell
tell window 3
click checkbox 2
end tell
end tell
end tell
end tell
--tell process system preferences
--if title of button 4 of window 1 is "Click the lock to make changes." 
--then set preferencesLocked to true
--click button "Click the lock to make changes."
--end if
end tell

Any help gratefully received.

Thanks

Ed,

Accessibility is now a separate pane of the Security Preferences Pane.

However, you can still set this systematically.

Full details here:

http://apple.stackexchange.com/questions/111903/allow-application-to-control-computer-assistive-devices-on-mavericks-via-termi

So in 10.8, I used the following to select “VPN” and then “Cisco IPSec” in the property sheet:


tell application "System Events"
		tell process "System Preferences"
			tell window 1
				click button 9
				--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 3
				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

In 10.9, this does not work, I get the following error message:
error “System Events got an error: Can’t get pop up button 2 of sheet 1 of window 1 of process "System Preferences". Invalid index.” number -1719 from pop up button 2 of sheet 1 of window 1 of process “System Preferences”

PLEASE HELP ME RESOLVE THIS!!!