Skip to content

Instantly share code, notes, and snippets.

@scooby
Created October 17, 2009 00:02
Show Gist options
  • Save scooby/212162 to your computer and use it in GitHub Desktop.
Save scooby/212162 to your computer and use it in GitHub Desktop.
Purpose: to generate a playlist from a Genius mix for use with an older iPod or to burn to CD. A genius mix, incidentally, is *not* the same as a Genius playlist.
(*****************************************************
Make a Genius mix into playlist
by Ben Samuel
This script is released into the public domain.
Purpose: to generate a playlist from a Genius mix for use with an
older iPod or to burn to CD. A genius mix, incidentally, is *not*
the same as a Genius playlist.
Requires: iTunes 9. Older versions don't have Genius Mixes, and
newer versions will probably confuse the UI scripting.
Ensure that, under System Preferences, Universal Access, that
"Enable Access for Assistive Devices" is checked.
*****************************************************)
tell application "iTunes"
activate
stop
end tell
tell application "System Events"
tell application process "iTunes"
-- Make sure Genius Mixes is selected.
tell first window's first splitter group's first splitter group's first scroll area's first outline
repeat with i in rows
if name of first static text of i is "Genius Mixes" then
select i
exit repeat
end if
end repeat
end tell
-- I could simply wait for the user to select a mix,
-- however, there's no (simple) way to find out what
-- button they clicked.
set mixes to {}
set button_list to {}
tell first window's first splitter group's first scroll area
repeat with e in buttons
set mixes to mixes & {"" & description of e}
set button_list to button_list & {e}
end repeat
end tell
set chosenMix to (choose from list mixes with title "Make a mix playlist" with prompt "Choose a Genius Mix to transcribe." without multiple selections allowed and empty selection allowed)
set chosenMix to first item of chosenMix
-- Click the button.
repeat with e in button_list
if description of e = chosenMix then
perform action "AXPress" of e
exit repeat
end if
end repeat
end tell
end tell
tell application "iTunes"
activate
-- Make sure we actually found the mix the user chose.
if player state is playing then
pause
-- Remove most of the description
if chosenMix begins with "(Playlist) " then
set chosenMix to (characters 12 through -1 of chosenMix) as text
end if
if chosenMix contains ", Based on:" then
set chosenMix to (characters 1 through ((offset of ", Based on:" in chosenMix) - 1) of chosenMix) as text
end if
set numItems to (choose from list {10, 20, 50, 100, 200, 500} with title "Make a mix playlist" with prompt "How many tracks do you want in the new playlist?" without multiple selections allowed and empty selection allowed)
set numItems to first item of numItems
set copynum to ""
-- Handle an existing playlist with the same name.
-- The user can easily combine playlists if needed.
repeat while exists playlist (chosenMix & copynum) of source "Library"
set copynum to " " & (copynum + 1)
end repeat
set pl to (make new playlist at source "Library" with properties {name:(chosenMix & copynum)})
-- It might be faster to copy the tracks straight
-- from current playlist, but this is good enough.
repeat with i from 1 to numItems
set t to current track
if class of t is file track then
set loc to (location of t) as alias
add loc to pl
end if
next track
end repeat
-- Show the user the new playlist and notify that the
-- operation is complete by playing.
reveal first track of pl
play
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment