Below is a script I run on a client computer (part of a question I asked about scripting the input menu yesterday). The script works, but only if I move the mouse or hit a key on the keyboard while it is running. If not, the script will pause at random places, usually when attempting to tell something to the System Preferences. Anyone encounter this before? Thanks.
try
tell application "System Preferences"
activate
end tell
end try
-- set expose
tell application "System Preferences"
set current pane to pane "com.apple.preference.expose"
-- use system events for GUI scripting
tell application "System Events"
tell process "System Preferences"
-- select different Expose keys to eliminate the F9 conflict with Lotus Notes
perform action "AXPress" of pop up button 1 of group 2 of window "Exposé"
pick menu item "F10" of menu of pop up button 1 of group 2 of window "Exposé"
delay 3
perform action "AXPress" of pop up button 2 of group 2 of window "Exposé"
pick menu item "F11" of menu of pop up button 2 of group 2 of window "Exposé"
delay 3
perform action "AXPress" of pop up button 3 of group 2 of window "Exposé"
pick menu item "F12" of menu of pop up button 3 of group 2 of window "Exposé"
end tell
end tell
end tell
-- set keyboard and mouse
tell application "System Preferences"
set current pane to pane "com.apple.preference.keyboard"
-- use system events for GUI scripting
tell application "System Events"
tell process "System Preferences"
click radio button "Keyboard Shortcuts" of tab group 1 of window "Keyboard & Mouse"
-- activate full keyboard access to tab buttons and access menus through keyboard
if (value of checkbox "Turn on full keyboard access" of tab group 1 of window "Keyboard & Mouse" = 0) then
click checkbox "Turn on full keyboard access" of tab group 1 of window "Keyboard & Mouse"
end if
end tell
end tell
end tell
-- set quicktime
tell application "System Preferences"
set current pane to pane "com.apple.preference.quicktime"
-- use system events for GUI scripting
tell application "System Events"
tell process "System Preferences"
click radio button "Connection" of tab group 1 of window "QuickTime"
-- set Quicktime connection speed
perform action "AXPress" of pop up button 1 of tab group 1 of window "QuickTime"
pick menu item "Intranet/LAN" of menu of pop up button 1 of tab group 1 of window "QuickTime"
end tell
end tell
end tell
try
tell application "System Preferences"
quit
end tell
end try
Most of your code here is not Tiger compatible, so I can’t help too much. But to give you some ideas, I rewrote the first part of your script so that it works in Tiger (haven’t tried it with Panther, although I think it should work) In your case System Preferences might accidentally be losing keyboard focus. So my prescription is to nest the entire script in a System Preferences tell block, and add “activate” where needed within the script. Also, delays are probably aren’t necessary here, and should be avoided.
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.expose"
tell application "System Events" to tell process "System Preferences" to tell group 2 of window 1
click pop up button 1
click menu item "F10" of menu of pop up button 1
click pop up button 2
click menu item "F11" of menu of pop up button 2
click pop up button 3
click menu item "F12" of menu of pop up button 3
end tell
end tell
I appreciate the feedback. Unfortunately, the delays appear to be necessary. At least two of them. Without the first two, the script kept getting ahead of the application, and failed to click the second pop-up menu. Adding the delay fixed that error. I am writing the script for Panther, so having it Tiger compatible is not a priority at this point. I’m confused about the System Preferences block. I thought the original script was in such a block. Guess I’ll have to relook at it. Thanks very much.
When you say “the script kept getting ahead of the application” are you talking about your code or mine? My code only uses “click” whereas yours uses “pick” and "perform action “AXPress” etc. which could make a difference. Try this (untested-but-should-work) code instead:
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.expose"
tell application "System Events" to tell process "System Preferences" to tell group 2 of window 1
click pop up button 1
click menu item "F10" of menu of pop up button 1
click pop up button 2
click menu item "F11" of menu of pop up button 2
click pop up button 3
click menu item "F12" of menu of pop up button 3
end tell
set current pane to pane "com.apple.preference.keyboard"
tell application "System Events" to tell process "System Preferences" to tell tab group 1 of window 1
click radio button "Keyboard Shortcuts"
tell checkbox "Turn on full keyboard access" to if value = 0 then click
end tell
set current pane to pane "com.apple.preference.quicktime"
tell application "System Events" to tell process "System Preferences" to tell tab group 1 of window 1
click radio button "Connection"
click pop up button 1
click menu item "Intranet/LAN" of menu of pop up button 1
end tell
end tell