My goal is to script several of the system preferences in Panther. Of course this basically has to be done with GUI scripting. Thus far I have been able to script all the panes I need except one. I am having problems with the International Pane, specifically the Input Menu. I would like to script checking the Character Palette and Keyboard Viewer. Here is what I have thus far:
try
tell application “System Preferences”
activate
end tell
end try
tell application “System Preferences”
set num to 0
set current pane to pane “com.apple.Localization”
tell application “System Events”
tell process “System Preferences”
repeat with x in (get every row of table 1 of scroll area 1 of tab group 1 of window “International”)
repeat with t in (get every button of x where title of button of x is not equal to “Keyboard”)
set s to (get title of t) as string
if s is equal to “Character Palette” or s is equal to “Keyboard Viewer” then
click checkbox 1 of x
set num to num + 1
end if
if num is greater than 1 then exit repeat
end repeat
end repeat
end tell
end tell
end tell
A little ragged but almost working. Two problems. First, it won’t exit the loop once num hits two. That would prevent it from scanning through 95 more rows (I have to loop because the order of rows changes based on what is selected). Second, even though it does click the checkbox on the first hit, it unchecks it on the second, even though that is not what the result log says it happening (the log says it is checking the individual boxes). Anyone have any thoughts?
Well, the num test should be in the outer repeat loop, so that fixes that.
try
tell application “System Preferences”
activate
end tell
end try
tell application “System Preferences”
set num to 0
set current pane to pane “com.apple.Localization”
tell application “System Events”
tell process “System Preferences”
click radio button “Input Menu” of tab group 1 of window “International”
repeat with x in (get every row of table 1 of scroll area 1 of tab group 1 of window “International”)
repeat with t in (get every button of x where title of button of x is not equal to “Keyboard”)
set s to (get title of t) as string
if s is equal to “Character Palette” or s is equal to “Keyboard Viewer” then
click checkbox 1 of x
set num to num + 1
end if
end repeat
if num is greater than 1 then exit repeat
end repeat
end tell
end tell
end tell
However, I’m still stuck between the Applescript results and what is really happening. The results say that the checkbox in row 3 is being clicked, then the checkbox in row 4 is being clicked. However, when you actually watch the System Preferences, the checkbox in row 3 is being checked on then off. Nothing is happening to row 4. Odd.
Alright, this is what I have, comments included. It ‘should’ work. The event log in the Script Editor outputs this command as the one being run:
click checkbox 1 of row 4 of table 1 of scroll area 1 of tab group 1 of window “International”
Again that should be correct. But it won’t check the box. It’s driving me a little batty.
tell application “System Preferences”
– counter to end loop
set num to 0
– hold input variables to test against
set chaPal to “Character Palette”
set keyVie to “Keyboard Viewer”
set current pane to pane “com.apple.Localization”
tell application “System Events”
tell process “System Preferences”
click radio button “Input Menu” of tab group 1 of window “International”
– start loop to read all rows in table
repeat with tRow in (get every row of table 1 of scroll area 1 of tab group 1 of window “International”)
– start loop to find title of button for comparison. ignore Keyboard.
repeat with tButton in (get every button of tRow where title of button of tRow is not equal to “Keyboard”)
– store title of button
set bTitle to (get title of tButton) as string
– look for input variables in button title
if bTitle is equal to chaPal or bTitle is equal to keyVie then
– found a button. test to see if check box checked.
if value of checkbox 1 of tRow is equal to 0 then
click checkbox 1 of tRow – check the box
end if
– increment counter to eliminate iterating through every row
set num to num + 1
end if
end repeat
– escape loop once two input variables found
if num is greater than 1 then exit repeat
end repeat
end tell
end tell
end tell
Jacques, you are a man among men. Your script works to perfection. That is a much more efficient loop than I included. The key seems to have been selecting the checkbox then clicking it. No clue I would need both steps. Much appreciated.