I've actually done this in a script or two and here's an example that should get you going:
set value of text field 2 of window 1 to "someString"
Hope this helps,
Patrick Salo
Macs @ Intel Program
Information Technology
Intel Corporation
I've simply configured a correct IPSec VPN profile in 10.6, then
On Aug 25, 2009, at 3:42 PM, Thomas Larkin wrote:
exported it. When you do so, it exports the username, so I edited it
out of the XML file.
Here's my script below. I tested this without the Finder open (i.e.
already had the VPN profile imported, and selected). The "key code
48"'s are tabs, and then the "keystroke AccountName" would correctly
put the text in the "Account Name:" field.
However, when I import it, the VPN interface isn't selected, and no
matter of tabs will enter the data (and then there's the issue of
whether or not users have Full Keyboard Access turned on or not). I
need to figure out how to select the "VPN (IPSec)" interface in the
list on the left-hand side of the Network preference pane.
My AppleScript 1-2-3 book is 85 miles from where I'm at right now, so
I'm going to sleep on it, but if anyone has any suggestions, I'm all
ears...
do shell script "/usr/bin/defaults read /System/Library/CoreServices/
SystemVersion ProductVersion"
set osVersion to the result
--Script Action
tell application "System Events"
set UI_enabled to UI elements enabled
end tell
if UI_enabled is false then
do shell script "/usr/bin/touch /private/var/
db/.AccessibilityAPIEnabled" with administrator privileges
end if
if osVersion contains 10.6 then
set AccountName to the text returned of (display dialog "What is your
Network Account Name?" default answer "")
tell application "Finder"
activate
open document file "SnowLeopardVPN.networkConnect" of folder
"Shared" of folder "Users" of startup disk
tell application "System Preferences"
activate
tell application "System Events" to tell process "System
Preferences" to tell window "Network"
key code 48
key code 48
keystroke AccountName
click button "Apply"
end tell
end tell
end tell
end if
tell application "Finder"
activate
delete document file "SnowLeopardVPN.networkConnect" of folder
"Shared" of folder "Users" of startup disk
end tell
See, that's just it, I have tried all manner of "text field x" and I
On Aug 25, 2009, at 4:08 PM, Salo, Patrick wrote:
keep getting "Can't get text field x of window "Network" of process
"System Preferences". Invalid index".
I've used the UIAccessibilityInspector to try to find out if that text
field is numbered, but it isn't as far as I can tell...
Ah okay, well this should do it for you then. Please note that this
script still needs some work to do a couple of things such as:
1. Select the VPN service in the table on the left
2. Comprehend the confirmation sheet (if it appears)
But if you already have the Network System Preferences up and the VPN
service already selected it should work be enough to get you going in
the right direction.
set AccountName to "jdoe"
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.network"
end tell
tell application "System Events"
tell process "System Preferences"
set value of text field 2 of group 1 of window 1 to AccountName
click button "Apply" of window 1
end tell
end tell
Patrick Salo
Macs @ Intel Program
Information Technology
Intel Corporation