table view with album and artist

Hi There,

first of all I want to thank everybody in this forum for precious help.

I’m doing a script which get all albums and their artist to populate a table and make a choice.

What I’ve done is:


on showAlbums()
	set text color of every data cell of every table column of table view "my_table" of scroll view "my_scroll" of window "choose" to "white"
	tell application "iTunes"
		set theList to {}
		set dupcheck to {}
		repeat with n in every file track of playlist "Phone"
			if (dupcheck does not contain n's album) then
				set end of theList to {n's album, n's artist}
				set dupcheck to dupcheck & {n's album, n's artist}
				
			end if
		end repeat
	end tell
	set theDataSource to make new data source at end of data sources with properties {name:"albums"}
	
	make new data column at end of data columns of theDataSource with properties {name:"Albums", sort order:ascending, sort type:alphabetical, sort case sensitivity:case sensitive}
	make new data column at end of data columns of theDataSource with properties {name:"Artist", sort order:ascending, sort type:alphabetical, sort case sensitivity:case sensitive}
	set data source of table view "my_table" of scroll view "my_scroll" of window "choose" to theDataSource
	append theDataSource with theList
	tell table view "my_table" of scroll view "my_scroll" of window "choose" to update
end showAlbums


this piece of code gets the artist and album of every track in my playlist phone, checks the duplicates and with result sets the data source for the table.

It works fine until I use it with a small playlist.

When I try to use this code with my whole library (1560 songs) it takes very very long time to finish.

Any suggestion to speed up?

Note: I’m pretty new of applescript so don’t blame me for my crappy code.

Thanks,
Max

Hi,

replace


 repeat with n in every file track of playlist "Phone"

with


set theTracks to every file track of playlist "Phone"
	repeat with n in theTracks

in the first form in each iteration all tracks are retrieved from iTunes,
in the second form the tracks are retrieved just once

Thanks a lot for your fast response but I save only few seconds with your solution. I need to improve much more.

I used a very fast code but I can get only album or artist not both.



			set albumList to album of every file track of playlist "Musica"
			set shortAlbumList to {}
			repeat with myAlbum in items of albumList
				if (shortAlbumList does not contain myAlbum) and (length of myAlbum is not 0) then
					set shortAlbumList to shortAlbumList & myAlbum
				end if
			end repeat



with this I get all albums title in a couple of seconds

I tried to work on this to get also the artist but no luck and don’t forget I have to set the data source with the result

Max

is this faster


tell application "iTunes"
	set newList to {}
	set theList to {album, artist} of every file track of playlist "myPlayList"
	repeat with n from 1 to count (item 1 of theList)
		set newEntry to {item n of item 1 of theList, item n of item 2 of theList}
		if {newEntry} is not in newList then
			set end of newList to newEntry
		end if
	end repeat
end tell

You rule!!! it works like a charm.

Thanks a billion,
Max