Anyone done any UI scripting? Stuck on AppleScript UIscripting

tlarkin
Honored Contributor

I am trying to accomplish something different, but I do have an Apple Script someone helped me write which prompts an end user for input. Though, it would be of my opinion to have zero user interaction and have it all automated. Can you give me an example of where this profile is stored and generated?

Anyway, here is the Apple Script to get a user to prompt to input text:

-- get the input information for the script set theName to text returned of (display dialog "Enter a base name for the images" default answer "ScreenImage" buttons {"Cancel", "Continue"} default button 2 with icon note) set imageFolderPath to choose folder with prompt "Please choose the folder where you want the images saved." set posix_imageFolderPath to POSIX path of imageFolderPath

This is an exert from my script that prompts the installer of the package to input information. Of course this is to a predefined path, so it is calling up that predefined path to input the text to.

I think there may be a better way to do what you want though.

4 REPLIES 4

Not applicable

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

RobertHammen
Valued Contributor II

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

RobertHammen
Valued Contributor II

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...

Not applicable

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