Can't get process "iTunes" to accept click at {x,y}. Any ideas?

I’m trying to automate the process of downloading app updates from iTunes.
Since there are no buttons or menu items involved, I guess the only option is to use a “click at{x,y}” command. But when I do that, nothing happens, except iTunes starts hogging 90% CPU. The script times out with no errors but iTunes keeps on eating the CPU. Any ideas guys?

tell application "System Events"
	tell process "iTunes"
		activate
		set frontmost to true
		tell first static text of row 7 of outline 1 of scroll area 2 of window "iTunes"
			set {xPosition, yPosition} to position
			set {xSize, ySize} to size
		end tell
		click at {xPosition + (xSize / 2), yPosition + (ySize / 2)}
	end tell
end tell

What are you trying to click? In my copy of iTunes 10.3.1, the static text in row 7 is “STORE”.

This selects and puts me through to the iTunes Store:

-- Assuming that iTunes is already running.
tell application "System Events"
	tell process "iTunes"
		-- Don't use 'activate' here. It would be directed at System Events, not iTunes.
		set frontmost to true
		tell window "iTunes"
			tell (first row of outline 1 of scroll area 2 whose value of static texts contains "iTunes Store")
				set value of attribute "AXSelected" to true
			end tell
		end tell
	end tell
end tell

Thanks Nigel.

It didn’t work but it put me on the right track so now I’ve got it working, but I’ve met a new problem. I want to automate the process of downloading iPhone app updates, that’s why I needed to find a way to get to them :slight_smile:
Now I’ve successfully “clicked” the Apps button in scroll area and then the “x Updates Available” button (at the bottom of the screen) which takes me to a page with all the updated apps. The button I want to click next is “Download all available downloads”. Unfortunately UI Browser crashes when I try to see what’s inside Web Area “iTunes Store” and UIElementsInspector doesn’t help much.

Here’s my script so far:

tell application "System Events"
	tell process "iTunes"
		tell window "iTunes"
			tell scroll area 2
				try
					tell outline 1
						set selected of (first row whose value of static text 1 begins with "Apps") to true
					end tell
				end try
			end tell
			try
				click (first button whose title ends with "Updates Available")
			end try
			tell UI element 1
-- This is where I'm lost. How can I talk to the button?
			end tell
		end tell
	end tell
end tell

Here’s what UIElementsInspector has to say of the button in question:
<AXApplication: “iTunes”>
<AXWindow: “iTunes”>
<AXWebArea: “iTunes store”>
<AXLink: “Download All Free Updates”>

Attributes:
AXRole: “AXStaticText”
AXSubrole: “(null)”
AXRoleDescription: “text”
AXEnabled: “1”
AXTitle: “(null)”
AXSize: “w=97 h=28”
AXValue: “Download All Free Updates”
AXParent: “<AXLink: “Download All Free Updates”>”
AXWindow: “<AXWindow: “iTunes”>”
AXTopLevelUIElement: “<AXWindow: “iTunes”>”
AXPosition: “x=1368 y=189”
AXChildren: “<array of size 0>”
AXDescription: “(null)”
AXFocused: “0”
AXVisited: “0”

Actions:
AXPress - press
AXShowMenu - show menu<AXApplication: “iTunes”>
<AXWindow: “iTunes”>
<AXWebArea: “iTunes store”>
<AXLink: “Download All Free Updates”>

Attributes:
AXRole: “AXStaticText”
AXSubrole: “(null)”
AXRoleDescription: “text”
AXEnabled: “1”
AXTitle: “(null)”
AXSize: “w=97 h=28”
AXValue: “Download All Free Updates”
AXParent: “<AXLink: “Download All Free Updates”>”
AXWindow: “<AXWindow: “iTunes”>”
AXTopLevelUIElement: “<AXWindow: “iTunes”>”
AXPosition: “x=1368 y=189”
AXChildren: “<array of size 0>”
AXDescription: “(null)”
AXFocused: “0”
AXVisited: “0”

Actions:
AXPress - press
AXShowMenu - show menu

Help please?

Hi, Monostratos.

I’ve enabled the “Apps” line in my iTunes Preferences, but the display produced when it’s selected doesn’t have an “Updates Available” button, no doubt because I don’t have an iTunes Store account and have never downloaded anything.

if you’re saying that the button you want is part of the “Web page” display, then by analogy with the stuff I can see under “iTunes Store”, it should be somewhere in the hierarchy of UI element 1 of scroll area 1 of the window. The script below might find it for you. It’s quite slow, but it should eventually return a reference which you can then either copy into your own script or use to derive a search filter.

tell application "System Events"
	tell process "iTunes"
		set frontmost to true
		tell window "iTunes"
			set ec to entire contents of UI element 1 of scroll area 1
			repeat with i from 1 to (count ec)
				set thisElement to item i of my ec
				try
					if (value of thisElement's attribute "AXValue" is "Download All Free Updates") then return thisElement
				end try
			end repeat
			return "No result"
		end tell
	end tell
end tell

Thanks again, Nigel.

UI element 1 returns an empty list when doing a “get entire contents”. I’m getting a feeling that the iTunes Store is off limits for scripters?
By the way I discovered that the “X available updates” button sometimes has the name “Check for updates” so I’ve rewritten the criteria to (ends with “updates”). But you probably don’t have that either if you don’t have any apps downloaded.

Morten

Well I do have a “Check for updates.” button, but clicking it brings up a sign-in dialog. And I don’t have an iPhone. :wink:

Sorry I can’t be of more help. Good luck ” but if you’re getting an empty list for the entire contents of ‘UI element 1’, then it could indeed be that the stuff on that screen is unreachable by script. :frowning: