• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Example: Script to randomize random smart playlists in iTunes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Example: Script to randomize random smart playlists in iTunes


  • Subject: Example: Script to randomize random smart playlists in iTunes
  • From: Stephen Jonke <email@hidden>
  • Date: Mon, 12 Jan 2004 15:56:20 -0500

How does one title this in a clear way? What I mean is if you have smart playlists that limit tracks to some number of tracks and are set to select those tracks randomly and has live updating enabled, then you can repopulate the list by selecting all the tracks and deleting them, which will then refill with a new random selection of tracks. I wanted to make it easy to do and so wrote this script that will re-randomine all smart playlists that have a name containing the word "Random".

In order for this to behave as expected your smart playlist must have a name containing the word "Random" (ex. "Random Children's Music"), must be limited to some number of tracks with tracks selected randomly, and have live updating enabled. Put the following script in your ~/Library/iTunes/Scripts folder or wherever convenient:

------------------------------------------------------------------------ -------------------
tell application "iTunes"
set smartLists to every user playlist whose smart is true and name contains "Random"

repeat with x in smartLists
if player state is playing then
delete (every track of x whose database ID is not (get database ID of current track))
else
delete (every track of x)
end if
end repeat
end tell
------------------------------------------------------------------------ -------------------

It's worth noting that, in a good example of the wackiness of AppleScript, the partial line, "get database ID of current track" MUST have the "get" and yet, conversely, "every track of x" must NOT have "get" in front of it!! Why? Only the Shadow knows.... If you try it otherwise you'll find you get an error.

You might ask why you would set up a smart playlist like this rather than just using the "randomize" button in iTunes. The answer is that with the above type playlists you can rearrange tracks, even on the fly, as you see fit - you can't rearrange tracks if you use the random play (aka "shuffle") button. It's nice to be able to manually tweak a random selection of tracks.

FYI, there is a way to allow a random play MODE playlist to be tweakable, but it is unintuitive (it involves that mysterious "Copy to Play Order" item you may have seen on occasion if you bring up the contextual menu on a track in a playlist - do that, then turn off random play, and the random order will still be intact but it won't be in random play mode and you'll be able to move tracks around. I think my approach is much more convenient and also a heck of a lot easier to explain to my wife.

Steve
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: script keeps sending events to remote machine
  • Next by Date: Re: Images and FMP
  • Previous by thread: Re: Scripting Illustrator 10
  • Next by thread: Indesign Question
  • Index(es):
    • Date
    • Thread