Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > AppleScript: Get every a list of every album in iTunes with no repeats

AppleScript: Get every a list of every album in iTunes with no repeats
Thread Tools
Mac Elite
Join Date: Sep 2000
Location: 'round the corner
Status: Offline
Reply With Quote
Dec 8, 2002, 02:58 PM
 
so, i set up this little script to get every name of every track's album and just show them back in dialogs, one after another. I want the list but I also want it to remove repeats and nulls...how can I?
[php]
tell application "iTunes"
set item_list to the album of every track of playlist 1 as list
repeat with i from 1 to number of items in the item_list
set this_item to item i of the item_list
display dialog this_item
end repeat
end tell
[/php]

EDIT: Trying out the PHP vCode, whatever thing
     
Mac Elite
Join Date: May 1999
Location: San Jose, CA
Status: Offline
Reply With Quote
Dec 9, 2002, 03:31 AM
 
Typically you need to iterate through the list manually eliminating duplicates and nulls.

Fortunately, the process isn't that hard. The following script adds a 'FilterList' procedure that eliminates empty and duplicate entries. Simply run the full list through the filter and you're all set:

Code:
on filterList(theList) -- initialize a new list variable set newList to {} --loop through the list repeat with anItem in theList -- coerce each list item to a string set thisItem to anItem as string -- check it's not empty if thisItem is not "" then -- and check it's not already in the output list if thisItem is not in newList then -- if we get here, it's a new, unique item, so add it to the list set newList to newList & {thisItem} end if end if end repeat -- now return the truncated list return newList end filterList tell application "iTunes" set item_list to the album of every track of playlist 1 as list set item_List to filterList(item_list) repeat with this_item in item_list display dialog this_item end repeat end tell
Note I've also simplified the display dialog code to use a 'repeat with this_item in item_list' syntax. AppleScript will automatically iterate through a list assigning each item to a variable, saving you the bother of having to do it yourself.

(corrected layout formatting)
(Last edited by Camelot; Dec 9, 2002 at 03:40 AM. )
Gods don't kill people - people with Gods kill people.
     
Mac Elite
Join Date: Sep 2000
Location: 'round the corner
Status: Offline
Reply With Quote
Dec 9, 2002, 06:49 AM
 
Thanks, I found some other scripts too, thanks again!
     
Mac Elite
Join Date: Sep 2000
Location: 'round the corner
Status: Offline
Reply With Quote
Dec 9, 2002, 04:49 PM
 
It says that album_list is not defined, anyone help me please?
[PHP]
tell application "iTunes"
tell source "Library"
tell playlist "Library"
set the master_list to the album of every track
set album_list to {}
repeat with i from 1 to the count of the master_list
set this_album to (item i of the master_list) as string
if the album_list does not contain this_album and ¬
this_album is not "" then
set the end of the album_list to this_album
end if
end repeat
end tell
end tell
end tell
[/PHP]
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Dec 9, 2002, 05:26 PM
 
Originally posted by Nebagakid:
It says that album_list is not defined, anyone help me please?
[PHP]
tell application "iTunes"
tell source "Library"
tell playlist "Library"
set the master_list to the album of every track
set album_list to {}
repeat with i from 1 to the count of the master_list
set this_album to (item i of the master_list) as string
if the album_list does not contain this_album and ¬
this_album is not "" then
set the end of the album_list to this_album
end if
end repeat
end tell
end tell
end tell
[/PHP]
I just copied and pasted the above code into Script Editor, and it worked fine. So I have no idea what your problem is. Is there anything around it that might be screwing it up?
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Mac Elite
Join Date: Sep 2000
Location: 'round the corner
Status: Offline
Reply With Quote
Dec 9, 2002, 08:08 PM
 
yeah, it works really well for me in script editor, it does some weird thing though where it says it can not get the total result...or something like that::::

[PHP]
No result was returned from some part of this expression. (-2763)
[/PHP]

so, why aint it working in apple script studio...hmmmmmm?
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:56 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2