Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'My iPod Mini Random Music Filling Scripts' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
My iPod Mini Random Music Filling Scripts
Authored by: TigerKR on Aug 16, '04 09:40:01PM
It works in two parts, the first part creates a random playlist from a shuffled library of all of your music (using only checked tracks) up to a 3.5 GB size (leaves a little room on the mini for files), and then plays that playlist:

tell application "iTunes"
	
	if (exists user playlist "Completely Random") then
		delete user playlist "Completely Random"
	end if
	-- deletes existing Completely Random playlist if it exists
	
	set mainLibrary to get (a reference to library playlist 1)
	set shuffle of mainLibrary to true
	set shuffle of mainLibrary to false
	set shuffle of mainLibrary to true
	-- shuffles the main iTunes library
	
	copy (get a reference to (make new user playlist with properties {name:"Completely Random"})) to randomLibrary
	set i to 1
	tell mainLibrary
		repeat while (size of randomLibrary is less than 3.75E+9)
			try
				if (file track i is enabled) then
					duplicate file track i to randomLibrary
				end if --> if the song has been checked for playback
				set i to i + 1
			end try
		end repeat
	end tell
	-- copies the first 3.5GB of music from the shuffled iTunes library into the new Completely Random playlist
	
	set shuffle of mainLibrary to false
	set view of browser window 1 to randomLibrary
	play randomLibrary
	-- unshuffles main iTunes library and plays new Completely Random playlist
	
end tell
The second part wipes your iPod, and then transfers your new Completely Random playlist to your iPod:

tell application "iTunes"
	
	repeat with i from 1 to the count of sources
		if the kind of source i is iPod then
			set thePod to the name of source i as text
		end if
	end repeat
	-- find the iPod
	
	tell source thePod
		repeat with thePlaylist from 1 to the count of user playlists
			delete user playlist thePlaylist
		end repeat
	end tell
	-- delete every playlist in the iPod	
	
	tell source thePod
		delete every track of playlist thePod
	end tell
	-- delete every track in the iPod	
	
	make new user playlist at source thePod with properties {name:"Completely Random"}
	duplicate (every track in user playlist "Completely Random") to library playlist 1 in source thePod
	duplicate (every track in user playlist "Completely Random") to playlist "Completely Random" in source thePod
	-- copy Completely Random iTunes playlist into new playlist Completely Random in the iPod
	
end tell
Then you can access these scripts from the iTunes menu by saving them using (AppleScript) Script Editor into ~/Library/iTunes/Scripts/

[ Reply to This | # ]