UI Scripting: Tab & Drop Menu Selection

Hi Experts ;),

I don’t have any experience writing script but I am learning; hope someone can guide me a little if you don’t mind.

I was able to bring up a language preference window, but don’t know how to write a script to click “Reduce PinYi” under the “Mode” tab.

Any help is really appreciated!!

wec12

Model: MacBook C2D
Browser: Firefox 2.0.0.8
Operating System: Mac OS X (10.4)

gidday wec12

whats the application your using?, maybe I can help.

you could try using either of these two products, to help you GUI script.

http://prefabsoftware.com/uibrowser/

http://developer.apple.com/samplecode/UIElementInspector/index.html

heres some info, ideas:

http://www.mactech.com/articles/mactech/Vol.21/21.06/UserInterfaceScripting/index.html

Thanks for the reply, Budgie.

I am using English as my primary system language and Chinese as my second. I believe there is a bug inside the Chinese language; although I already chose “Delete Hanzi” (under the drop menu), every time I restart my MacBook it turns back to “Reduce PinYin” (but it still shows “Delete Hanzi”). So the script would be launch everytime I start up the system and try to “refresh/reselect” the “Delete Hanzi”.

I do have UIElement from Apple installed in my MacBook and also checked the link you gave me; honestly, I really don’t know where to start. Mind guide me a little? Thank you very much again.

where are the two windows you are showing in your links?, are they in system prefs?

Budgie, you have to check “HanYi” of “Traditional Chinese” under “Input Menu” of "International " in the system preference. Thanks again :slight_smile: .

hmmmmm, ive only got Hanin, Cangjie, Jianyi, Dayi(Pro) and Pinyin

clicking on any of these doesn’t bring up either of the two menu windows you are showing?

im running OSX Tiger 10.4.10 from G5 2Ghz PPC,

found the windows, duhh, wasnt looking in the right place.

Really sorry about the confusion, Budgie.

Following the steps, thanks:

  1. Check “Hanin” of “Traditional Chinese” under “Input Menu” of "International " in the system preference.
  2. Switch English(flag) to Hanin.
  3. Click the selected Hanin icon on the menu extra. You should be able to see Preferences, then click Preference. Now the window should show up.

Please let me know if you still have question (sorry about my stupidity again). Thanks a bunch!!

haven’t forgotten you, ive run into a wee snag, maybe some one else can help me past it, having a problem clicking the button “Modes” in he window that pops up after the script has run, any ideas please, tried a variety of ideas but all have failed.

UI Element Insp returns the below for the window in question.

<AXApplication: “TCIMPrefsTool”>


<AXRadioButton: “Modes”>

Attributes:
AXRole: “AXRadioButton”
AXRoleDescription: “radio button”
AXParent: “”
AXTitle: “Modes”
AXFocused (W): “0”
AXValue: “0”
AXEnabled: “1”
AXWindow: “”
AXTopLevelUIElement: “”
AXPosition: “x=595 y=318”
AXSize: “w=60 h=24”

Actions:
AXPress - press

Heres the script so far:

------ THIS WILL CHECK TO SEE IF Enable access for assistive devices IS ON  std ------
tell application "System Events" to set isUIScriptingEnabled to UI elements enabled
if isUIScriptingEnabled = false then
	tell application "System Preferences"
		activate
		set current pane to pane "com.apple.preference.universalaccess"
		display dialog "Your system is not properly configured to run this script.  
         Please select the \"Enable access for assistive devices\" 
         checkbox and trigger the script again to proceed."
		return
	end tell
end if
---- THIS CHANGES THE  PREFS ----
tell application "Finder"
	activate
end tell
tell application "System Events" to tell menu bar 1 of application process "SystemUIServer"
	repeat with _menu from 1 to count menu bar items
		tell menu bar item _menu to if (get value of attribute "AXDescription") is "text input menu extra" then
			click
			(click menu item "Hanin" of menu 1)
			delay 0.5
			keystroke "U" using {option down, shift down}
			delay 4
			--having a wee bit of trouble getting the button "Modes" to click, working on it though
			--some advice here please.
			exit repeat
		end if
	end repeat
end tel

Budgie,

Actually, I was trying to use another way to overcome the “click-ness of the Mode” earlier this morning.

If the pref window which we are targeting at is opened, you press “tab once”, then “right arrow twice”, then press “space”, the Mode tab will open. However, I don’t know how to write the script. Hope this stupid method helps.

Thanks again.

try this

tell application "System Events"
	keystroke tab
	key code (ASCII character 29) -- right arrow
	key code (ASCII character 29)
	key code (ASCII character 32) -- space
end tell	

most deffinitly not a stupid idea, it’s the clue I was after, the above didnt do it for me so changed to

tell application "System Events"
				keystroke tab
				key code 124 -- right arrow
				key code 124
				key code 49 -- space
			end tell

nearly their…

My Dearest Budgie, :smiley:

Really can’t thank you more for all your big helps. I am now able to “refresh” the pref and run the script on the startup. Every time I saw the running process, I’ll remember all you kind help :wink: .

REALLY REALLY REALLY APPRECIATE!!

Have a nice day,

wec12

most welcome, enjoyed it myself, have fun :smiley: