Here is a segment of script where I am trying to click the “Import Settings…” button in the General Preferences window.
I cannot get the button clicked.
I get:
Result:
error “System Events got an error: Can’t get button "Import Settings." of window "General Preferences" of application process "iTunes".” number -1728 from button “Import Settings.” of window “General Preferences” of application process “iTunes”
Help please.
Using MacOSX Lion 10.7
It’s button 1 of window 1 of process “iTunes”
Here is the code I was trying. It returned an error
tell application “System Events”
tell application process “iTunes”
set frontmost to true
click menu item “Preferences.” of menu 1 of menu bar item “iTunes” of menu bar 1
tell window “General Preferences”
click button “General” of tool bar 1
click button “Import Settings.”
end tell
end tell
end tell
I also tried
click button 1, 2, 3, 4 all of which do not work.
Button 1 is the OK button
Button 2 is the Cancel button
Mac OSX Lion 10.7 iTunes 10.4.1
I can’t find a number to correspond correctly to the “Import Settings…” button
Import Settings is the first button. Your problem is with the menu part. The Preferences menu item is in the second menu. The first menu is the Apple menu. Change your code to
tell application "System Events"
tell application process "iTunes"
set frontmost to true
click menu item "Preferences." of menu 2 of menu bar 1
repeat until exists window "General Preferences" --do this so that the code doesn't overtake your GUI reactions
delay 0.02
end repeat
--don't use the line ' click button "General" of tool bar 1 ' because if the preferences weren't on the General tab, then the window wouldn't be called "General Preferences"
click button 1 of window 1
end tell
end tell
end tell
I don’t use menu bar items, mainly because its extra code that is not necessary.
You could also use:
tell application "System Events"
tell process "iTunes"
keystroke "," using command down
end tell
end tell
Now you don’t have to worry about localized string either.
iTunes 10.4.1, on Lion:
--This snippet assumes iTunes is running, and itsw General Preferences Pane is open.
-- It first opens the Import Settings window, then changes the Setting to 160 kbps.
set wantedsetting to "High Quality (160 kbps)"
tell application "iTunes" to activate
tell application "System Events"
click button "Import Settings..." of group 1 of window "General Preferences" of application process "iTunes" of application "System Events"
--delay 1 -- not needed
--set oldval to value of pop up button 2 of window "Import Settings" of application process "iTunes" of application "System Events"
--display dialog oldval
click pop up button 2 of window "Import Settings" of application process "iTunes" of application "System Events" -- select the button, or it won't take a menu click
click menu item wantedsetting of menu of pop up button 2 of window "Import Settings" of application process "iTunes" of application "System Events"
end tell
return