 |
 |
AppleScript: Get every a list of every album in iTunes with no repeats
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: 'round the corner
Status:
Offline
|
|
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
|
|
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
|
|
Thanks, I found some other scripts too, thanks again! 
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: 'round the corner
Status:
Offline
|
|
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
|
|
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
|
|
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? 
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|