Build list issue & progress indicator?
Hello,
I am writting a script and while it works properly, i was wanting to add some features so that it is more user friendly.
The main issue is that i have a loop that goes through the library and creates a list of all the albums in the library. The problem is that if you have 200 songs it isnt an intensive loop, but for someone with over 3000 songs, it can take some time. Here is the code:
set this_playlist to the view of browser window 1
tell this_playlist
repeat with i from 1 to the count of tracks
tell track i
set theAlbum to (album of track i of this_playlist) as string
if theAlbum is in theAList then
--do nada
else if theAlbum is "" then
--do nada
else
set the end of the theAList to theAlbum
end if
end tell
end repeat
from here theAList is then passed to a subroutine, which uploads the selected album to an iPod and once that is executed the whole program is looped again to allow you to add more albums to the iPod.
I know that i can build a list of albums faster using this code:
set theLibrary to view of browser window 1
set theList to (album of every track in theLibrary)
choose from list theList with prompt "this is a test"
but i cannot figure out a way to remove the duplicate entries.
I would rather use the last bit of code as it is much faster and then remove the duplicates from theList, but I am not sure how to do that.
Also, is there any way to do a progress indicator with applescript. It would be quite a useful thing if i had to go the first route.
Thanks,
JO
[1732 byte] By [
juniorop] at [2007-11-9 13:40:33]

# 1 Re: Build list issue & progress indicator?
hi JO,
you cannot do progress bars using the "vanilla" form of applescript but if you have a look at Smile (http://www.satimage.fr/software/en/softx.html#smile) or maybe Applescript Studio (available as part of the dev tools for os X) then you can extend the dialog capabilites to include your bar..
Re your duplicate list items... have you considered creating another list using your first one as a seed..
set finallist to {}
repeat with analbum in thelist
if finallist does not contain analbum then
copy analbum to end of finallist
end if
end repeat
(note.. Macless at work so cannot check syntax but theory is sound)
also you may get a bit of a speed increase if you use a reference (http://www.malcolmadams.com/itunes/itinfo/selection01.shtml) to the library...
wonder if something like..
set theList to ((album of every track in theLibrary) not contained in thelist)
would work...will need to check that... no it does not :(
deeg at 2007-11-15 17:25:03 >

# 2 Re: Build list issue & progress indicator?
The Appearance OSAX by 24U software will do progress bars.
# 3 Re: Build list issue & progress indicator?
Thanks for the responses... When i get home I will look into both of those suggestions.
A progress bar would help, but i guess i am more concerned that i cannot build this list once and reference it every time i want to run the subroutine, which could be 20 to 30 times in one run of the script. It takes a library with 2000 songs almost 1 minute to build the list of albums on a 1 ghz g4 with a gig of ram, which is too long in my book for it to be usable. With a progress bar you would know that the script hasnt hung, but building the list once and only once would be the best way to solve this usability issue.
I thought of the same thing deeg... looping through the 1st list and remove dupes to make a second list, but i do not know how to access the data in the 1st list.
could you do something like:
tell application "iTunes"
set theLibrary to view of browser window 1
set theList to (album of every track in theLibrary)
repeat with i from 1 to the count of items in theList
set theItem to item i of theList
if theItem is in theList then
--do nada
else if theItem is "" then
--do nada
else
set the end of the theFList to theItem
end if
end repeat
choose from list theFList with prompt "this is a test"
end tell
Yet something doesnt seem to be right here...
I would assume this might be faster than sorting thru the itunes library...
The only other idea that i had was to write the list to a file via applescript and then load that file in as the list. would have to look into that.
Any ideas?
thanks,
JO
# 4 Re: Build list issue & progress indicator?
Originally posted by juniorop
tell application "iTunes"
set theLibrary to view of browser window 1
set theList to (album of every track in theLibrary)
repeat with i from 1 to the count of items in theList
set theItem to item i of theList
if theItem is in theList then
--do nada
else if theItem is "" then
--do nada
else
set the end of the theFList to theItem
end if
end repeat
choose from list theFList with prompt "this is a test"
end tell
you're very close :) the issue is with the first check you do with theItem.. you are checking if its in theList, which is where it came from so it will always be in there and so it never gets added to theFlist
this code works...
tell application "iTunes"
set theList to {}
copy (a reference to (get view of browser window 1)) to theLibrary
set theList to (album of every track in theLibrary)
set theFinalList to {}
repeat with anAlbum in theList
if theFinalList contains anAlbum then
--noop
else
set theFinalList to theFinalList & anAlbum
end if
end repeat
choose from list theFinalList with prompt "this is a test"
end tell
deeg at 2007-11-15 17:28:09 >

# 5 Re: Build list issue & progress indicator?
thanks Deeg...
It is soo much faster this way.. dont even think that i need to add a progress bar.. we shall see when i try it on my "big" library at home..
Thanks for the help :)
JO
# 6 Re: Build list issue & progress indicator?
you're welcome... it should be good for a 1000 or so albums, the fun starts when you start to get the "stack overflow" errors above that number but we will save that for later ;)
deeg at 2007-11-15 17:30:07 >
