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


Click here to return to the 'Using a Smart Playlist to sync small iPods' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Using a Smart Playlist to sync small iPods
Authored by: sjonke on Feb 20, '04 01:27:21PM
Mine's pretty simple. The trackPlaylist should be a smart playlist that selects tracks at random (or however) and is limited to some size (I have mine set to 1500 MB) and the albumPlaylist should be a regular playlist:

property trackPlaylist : "iPod Tracks"
property albumPlaylist : "iPod Albums"
property albumsPercent : 0.25

tell application "iTunes"
  delete every track of playlist trackPlaylist
  delete every track of playlist albumPlaylist
  delay 2
  
  if exists (window 1) then set view of window 1 to playlist albumPlaylist
  
  set theAlbums to {}
  repeat with x in every track of playlist trackPlaylist
    set currAlbum to album of x
    if theAlbums does not contain currAlbum then
      set theAlbums to theAlbums & currAlbum
      if (random number) < albumsPercent then
        duplicate (every track of playlist "Library" whose album is currAlbum) to playlist albumPlaylist
      end if
    end if
  end repeat
end tell
NOTE: if you put this in iTunes script menu then be sure to save it as an application and not a compiled script. When I run it as a compiled script from there, the "delay 2" seems to block iTunes and as a result the trackPlaylist doesn't update before the script starts iterating over it. It works fine as an application and it works fine as a compiled script from the shareware "FastScripts" menu. It takes about a minute to run on my 400 MHz iMac G3, but that is just an estimate - I haven't timed it.

---
--- What?

[ Reply to This | # ]

Using a Smart Playlist to sync small iPods
Authored by: filmsmith on Feb 20, '04 01:37:52PM

Dang. I never thought I'd have to say this but... yours is so much smaller and more efficient than mine.

Having compared the two, I see how to trim the bloat in mine, though I can only trim some. Mostly, I have extra lines to compensate for iTunes seemingly crappy 'Shuffle' system. However, a few lines in mine that I prefer are those that pass over tracks that aren't enabled and also includes tracks whose album fields are empty. I also threw in some stuff to update my iPod as soon as it's finished. Basically, I set this script to run when I wake up monday morning and by the time I'm ready to go, I have a newly randomized iPod with all the New Releases included.

I think I see why yours is faster than mine. Mine uses a brute force to try and find albums that haven't been chosen, so odds are good that, as the script nears completion, it will take longer to find unused albums. Yours seems to solve this with "if (random number) < albumsPercent then" though I'll need to test it this eve.

Thanks for hook-up. I'm always curious to see how other people tackle scrips.



[ Reply to This | # ]
Using a Smart Playlist to sync small iPods
Authored by: sjonke on Feb 20, '04 01:56:17PM

Regarding passing over tracks that aren't enabled, you get that for free by setting the smart playlist to only include enabled tracks! Use the smart playlist to do as much of the work as possible.

---
--- What?



[ Reply to This | # ]
Never mind! Here's the solution.
Authored by: sjonke on Feb 20, '04 01:59:27PM
Oh, never mind - I see what you mean. Good point. I changed the duplicate line to the following to resolve that:

duplicate (every track of playlist "Library" whose album is currAlbum and enabled is true) to playlist albumPlaylist

---
--- What?

[ Reply to This | # ]

Never mind! Here's the solution.
Authored by: filmsmith on Feb 20, '04 02:01:13PM

Look at that! Had no idea I could do it that way.

Thanks again!



[ Reply to This | # ]
Never mind! Here's the solution.
Authored by: sjonke on Feb 20, '04 02:12:23PM

There are some powerful constructs in Applescript, they're just poorly documented and inconsistently implemented. An application's dictionary only tells you half the story.

My script presumes you don't have two or more albums with the same name, though that is certainly possible. You could include the artist name in there (... and artist is someName) - I didn't put that in because it was easier/faster to just save the album name in a list and it's not an issue for my library.

---
--- What?



[ Reply to This | # ]