iTunes sorting

Hi,

I need some help with Applescript and iTunes. I want to sort all playlists (2500) in the same way.
It should be displayed title. The sortorder should be Album-Artist and to display the cover.

I am not able to achieve the desired changes. The script opens the popup and select the option title. But it is not possible to enable the selected option. Click or enter doesn’t work.
Any suggestions?

Here is the incomplete script.


tell application "System Events"
	tell process "iTunes"
		-- insert GUI Scripting statements here:
		activate
		tell window 1
			click pop up button 1
			tell pop over 1 of pop up button 1
				repeat until it exists
					delay 0.2
				end repeat
				tell table 1
					set selected of item 2 of rows to true
					tell item 2 of rows
						click
						-- keystroke (ASCII character 13)
					end tell
				end tell
			end tell
		end tell
	end tell
end tell

Hope someone can help me.

Kind regards

Berthold

When an UI Element doesn’t respond to Apple’s click most of the time it respond to a click issued by cliclick available at :
http://www.bluem.net/en/mac/cliclick/

Ask GUI Scripting for the position and the size of the target item then use these values to set the coordinates where cliclick will apply.

As I had some minutes available I was able to test :

tell application "iTunes" to activate

tell application "System Events"
	tell process "iTunes"
		-- insert GUI Scripting statements here:
		-- activate
		set frontmost to true
		tell window 1
			-- log (get properties of pop up button 1)
			click pop up button 1 # named "Morceaux" in French
			tell pop over 1 of pop up button 1
				repeat until it exists
					delay 0.2
				end repeat
				-- log (get its properties)
				tell table 1 to tell item 2 of rows
					set its selected to true
					-- log (get its properties)
					set {x, y} to its position
					set {w, h} to its size
					--click
					-- keystroke (ASCII character 13)
					do shell script "/usr/bin/cliclick c:" & (x + w div 2) & "," & (y + h div 2)
					--end tell
				end tell
			end tell # pop over.
		end tell # window 1
	end tell # process
end tell # application

Yvan KOENIG running Yosemite 10.10.4 in French (VALLAURIS, France) lundi 10 août 2015 11:47:59

Thank you for the hint and excuse for the late reply. My Mac had a total crash and I thereby other problems.
I will try and report the suggestion next week.

Kind regards Berthold

Thanks again for the hint. Now everything works. Here is the full script.


tell application "iTunes" to activate

tell application "System Events"
	tell process "iTunes"
		-- insert GUI Scripting statements here:
		set frontmost to true
		tell window 1
			-- log (get properties of pop up button 1)
			click pop up button 1 # named "Morceaux" in French
			tell pop over 1 of pop up button 1
				repeat until it exists
					delay 0.2
				end repeat
				-- log (get its properties)
				tell table 1 to tell item 2 of rows
					set its selected to true
					-- log (get its properties)
					set {x, y} to its position
					set {w, h} to its size
					--click
					do shell script "/usr/local/bin/cliclick c:" & (x + w div 2) & "," & (y + h div 2)
				end tell # table 1
			end tell # pop over.
			delay 0.5
			click pop up button 1 # open pop up again
			tell pop over 1 of pop up button 1
				repeat until it exists
					delay 0.2
				end repeat
				tell pop up button 1 # open pop up sorting
					set {x, y} to its position
					set {w, h} to its size
					--click
					do shell script "/usr/local/bin/cliclick c:" & (x + w div 2) & "," & (y + h div 2)
				end tell # pop up
				delay 0.2
				-- make sure that the first entry is selected
				do shell script "/usr/local/bin/cliclick kp:arrow-up"
				do shell script "/usr/local/bin/cliclick kp:arrow-up"
				do shell script "/usr/local/bin/cliclick kp:arrow-up"
				do shell script "/usr/local/bin/cliclick kp:arrow-up"
				do shell script "/usr/local/bin/cliclick kp:arrow-up"
				do shell script "/usr/local/bin/cliclick kp:arrow-up"
				-- select second entry
				do shell script "/usr/local/bin/cliclick kp:arrow-down"
				delay 0.2
				do shell script "/usr/local/bin/cliclick kp:return"
				delay 0.2
				if value of checkbox 1 is 0 then # if show cover is not selected
					tell checkbox 1
						set its selected to true
						set {x, y} to its position
						set {w, h} to its size
						--click
						do shell script "/usr/local/bin/cliclick c:" & (x + w div 2) & "," & (y + h div 2)
					end tell # checkbox
				end if
			end tell # pop over.
			click pop up button 1 # close pop up
		end tell # window 1
	end tell # process
end tell # application

Presumably, too many and too long delays built in. Here you can still optimize. Without delays it doesn’t work for me.

Kind regards

Berthold

I’m puzzled.

Some messages dated 2015/08/14 appear before mine dated 2015/08/10.

I made a few changes to your script and, more important, I added comments upon its behavior

tell application "System Events"
	if exists disk item "/usr/local/bin/cliclick" then
		set p2CliClick to "/usr/local/bin/cliclick"
	else if exists disk item "/usr/bin/cliclick" then
		set p2CliClick to "/usr/bin/cliclick"
	else
		error "It seems that Cliclick is not installed"
	end if
end tell

tell application "iTunes" to activate

tell application "System Events"
	tell process "iTunes"
		set frontmost to true
		tell window 1
			log (get class of UI elements) --> (*radio group, radio group, pop up button, button, button, button, slider, scroll area, button, text field, button, button, button, button, splitter group*)
			log (get name of pop up button 1) -- "Morceaux"
			click pop up button 1 # named "Morceaux" or "Albums" or "Artistes" . in French
			tell pop over 1 of pop up button 1
				repeat until it exists
					delay 0.1
				end repeat
				log (get class of UI elements)
				# If name of pop up button 1 is "Morceaux"
				--> (*table, pop up button, static text, pop up button, checkbox, checkbox, slider*)
				# If name of pop up button 1 is "Albums" 
				--> (*table, pop up button, static text, pop up button, static text, checkbox, pop up button*)
				tell table 1 to tell item 2 of rows
					set its selected to true
					set {x, y} to its position
					set {w, h} to its size
					--click in the pop up button entitled "Albums"
					do shell script p2CliClick & " c:" & (x + w div 2) & "," & (y + h div 2)
				end tell # table 1
			end tell # pop over.
			delay 0.3 # Here it enter an infinite loop if the delay is smaller.
			
			log (get name of pop up button 1) --> Now it's "Albums"
			click pop up button 1 # open pop up again
			tell pop over 1 of pop up button 1
				repeat until it exists
					delay 0.1
				end repeat
				tell pop up button 1 # open pop up sorting
					set {x, y} to its position
					set {w, h} to its size
					log (get its value) --> "Artiste"
					--click in the pop up button entitled "Artists"
					do shell script p2CliClick & " c:" & (x + w div 2) & "," & (y + h div 2)
				end tell # pop up
				delay 0.1
				
				-- make sure that the first entry is selected
				repeat 6 times
					do shell script p2CliClick & " kp:arrow-up"
				end repeat
				-- select second entry
				do shell script p2CliClick & " kp:arrow-down"
				delay 0.1
				do shell script p2CliClick & " kp:return"
				delay 0.1
				if value of checkbox 1 is 0 then # if show cover is not selected ?????????
					tell checkbox 1
						set its selected to true
						set {x, y} to its position
						set {w, h} to its size
						--click the checkbox
						do shell script p2CliClick & " c:" & (x + w div 2) & "," & (y + h div 2)
					end tell # checkbox
				end if
				
				log (get title of checkbox 1) --> (*Afficher les ajouts récents*)
				log (get value of pop up button 2) --> (*Année*)
				log (get value of pop up button 3) --> (*de l'année dernière*)
			end tell # pop over.
			click pop up button 1 # close pop up
		end tell # window 1
	end tell # process
end tell # application

As you may see, the check box which you describe as entitled “Show cover” is named “Afficher les ajouts récents” in French.
I’m not sure that checking it is useful here.

I made change upon instructions triggering cliclick because you installed it as “/usr/local/bin/cliclick”
when my sample was triggering it at “/usr/bin/cliclick”

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) dimanche 16 août 2015 20:37:00