Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

rjbs (4671)

  (email not shown publicly)
AOL IM: RicardoJBSignes (Add Buddy, Send Message)
Yahoo! ID: RicardoSignes (Add User, Send Message)

I'm a Perl coder living in Bethlehem, PA and working Philadelphia. I'm a philosopher and theologan by training, but I was shocked to learn upon my graduation that these skills don't have many associated careers. Now I write code.

Journal of rjbs (4671)

Tuesday May 31, 2005
08:10 PM

fixing my playlists with applescript

[ #24964 ]

So, some time ago I ranted about how happy I was with my Radio RJBS playlists. Basically, I have a playlist that's always eight hours of three-star music and sixteen hours of four- or five-star music. It's all "regular music," which by my definition is something like "not a musical, not noise, not spoken word, not classical." (My "Classical" genre, I admit, is really more like "music composed before 1900.") All the songs are selected by recency of last playing: less recently played songs are chosen over more recently played songs.

At some point, I realized that because I had sometimes gone on binge days of rating single artists, I ended up with that artist's last play dates clumped together. For some reason, I decided that the best way to fix this was by clearing the last played dates. This wasn't a horrible idea, since iTunes seems to have gotten over its old problems with sorting. It used to be that given ten songs that couldn't be sorted by your given criterion, it would sort by name. I believe it now picks a distributed sample, but I haven't bothered really researching this. It just seems better than it used to.

Anyway, given that I have a huge amount of certain artists, they started showing up in big clumps again. I was hearing nearly all Elvis Costello, DEVO, and Tom Waits. This wasn't so bad, but it meant that I'd always have these songs clumped together. (To some extent, this problem is fated to exist, as I've defined the playlists, but it needn't be so bad.)

On the bus on the way home, I brushed off my AppleScript and put a script together to distribute a selection of songs randomly across a given period of time. My first pass at this was hilarious, because I couldn't remember the silly AppleScript way to get a random number, and settled for building a list and using "some." It was great.

Anyway, here's what I settled on:

        set earliestDate to date "Tuesday, March 1, 2005 00:00:0 "
        set latestDate to date "Monday, May 30, 2005 00:00:0 "
        set totalRange to latestDate - earliestDate

        tell application "iTunes 4.8"
                set selectedSongs to selection
                repeat with song in selectedSongs
                        set played date of song to earliestDate + (random number from 1 to totalRange)
                end repeat
        end tell

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.