jag hittade detta som kanske kan vara till hjälp.
den används för att lägga till hela album i partyblandning. så man kanske kan modda den till en egen spellista och att bara ta en låt.
property path_to_xml : "~/Music/iTunes/iTunes\\ Music\\ Library.xml"
tell application "iTunes"
if player state is playing and special kind of current playlist is Party Shuffle then
-- selected track's Album?
if (count items of selection) is 1 and (get album of first item of selection) is not "" then
set chosen_album to (get album of first item of selection)
display dialog "Add tracks in the \"" & chosen_album & "\" Album to Party Shuffle?" with icon 1
else
-- choose an album from discrete list of all albums
set chosen_album to (choose from list (my get_albums()) with prompt "Select an Album..." without multiple selections allowed) as string
if chosen_album is "false" then return
end if
-- get all tracks of the Album
set these_album_tracks to (get every track of library playlist 1 whose album is chosen_album)
-- put the tracks into Party Shuffle
-- first delete tracks if they are already in Party Shuffle...otherwise they will not be re-added
delete (every track of current playlist whose album is chosen_album and index > (get index of current track))
-- now the business
set dbid to (get database ID of current track)
repeat with this_track in reverse of my tracks_sorted_by_track_number(these_album_tracks)
if (get database ID of this_track) is not dbid then my play_next_in_ps(this_track) -- don't re-add if a track is the current track
end repeat
set view of front browser window to playlist "Party Shuffle"
else
try
display dialog "The Party Shuffle playlist must be playing before adding new tracks to it..." buttons {"Cancel"} default button 1 with icon 2 giving up after 15
end try
end if
end tell
-- sort the tracks by track number
-- routine based on Apple's "ASCII_Sort"
-- http://www.apple.com/applescript/guidebook/sb...
on tracks_sorted_by_track_number(these_tracks)
tell application "iTunes"
set sorted_list to {}
set index_list to {}
set count_of_tracks to (count these_tracks)
repeat count_of_tracks times
set the low_item to ""
repeat with i from 1 to count_of_tracks
if i is not in the index_list then
set this_track to item i of these_tracks
set this_item to item i of these_tracks
if the low_item is "" then
set the low_item to this_item
set the low_item_index to i
else if (get this_item's track number) < (get low_item's track number) then
set the low_item to this_item
set the low_item_index to i
end if
end if
end repeat
set the end of sorted_list to the low_item
set the end of the index_list to the low_item_index
end repeat
end tell
return sorted_list
end tracks_sorted_by_track_number
-- based on routine written by J Nicholas Jitkoff, Blacktree.com, also
-- http://www.macosxhints.com/article.php?story=...
on play_next_in_ps(t)
tell application "iTunes"
set p to some playlist whose special kind is Party Shuffle
set i to index of current track
tell p
set ts to a reference to (every track whose index > i and index is less than or equal to (count tracks))
duplicate t to p
duplicate ts
delete ts
end tell
end tell
end play_next_in_ps
to get_albums()
set the_command to "perl -e 'local $/ = undef;my $s = <>;@thesealbums = ();%seen=();
while ($s=~m:<key>Album</key><string>(.*?)</string>:sg ) {
$g = ($1.\",\");
push (@thesealbums,$g) unless $seen{$g}++;
}
print sort @thesealbums;' " & path_to_xml
set g to text_to_list((do shell script the_command), ",")
if last item of g is "" then set g to items 1 thru -2 of g
return g
end get_albums
on text_to_list(txt, delim)
set saveD to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {delim}
set theList to every text item of txt
on error errStr number errNum
set AppleScript's text item delimiters to saveD
error errStr number errNum
end try
set AppleScript's text item delimiters to saveD
return (theList)
end text_to_list
hittade också (som va nytt för mig ) ett sätt för dig att göra ett kortkommando för ditt script.
Doug's AppleScripts for iTunes ♫ Assign Shortcut Keys to iTunes AppleScripts