Monday, January 26, 2009

Disco XT to iTunes: another nifty little AppleScript

Here's yet another AppleScript that swing DJs might find useful. Disco XT is a software program (now available for Mac and PC) that I, and from what I hear, many other swing DJs, use to play our sets. It's my first choice because it:
  • reads my iTunes library,
  • works with dual audio output, so I can preview songs in my headphones while playing a different tune over the main speakers, and
  • automatically loads songs from a cue and transitions between songs.
It also keeps a log of every song played. I like to save all my DJ sets as iTunes playlists, so I wrote an AppleScript that will pull a Disco XT playlist back in to iTunes. The program is a little bit kluggy because you can't copy directly from a Disco XT log file--you have to export it as text first. So to use the script, you need to do the following in order:
  1. Play a set using Disco XT.
  2. When you're done, export your log to a text file.
  3. Open that file.
  4. Highlight the songs that you want to copy into iTunes and hit apple-C to copy.
  5. Open your iTunes and run this script.
  6. A new playlist called "Disco XT playlist" will be generated. Since Disco only allows you to export the title and artist of the tracks that you played, there is no way to uniquely identify a track if you happen to have multiple versions (for instance, your 6 different recordings of the Basie band playing One O'Clock Jump). The script pulls all of them, so you'll need to look through the playlist and delete the tracks that you didn't actually play.
If anyone has suggestions for improving the AppleScript code below, please feel free to share. Or if you have a better way of doing the same task that doesn't use an AppleScript at all, I'd love to hear it.

Here's the code:
tell application "Finder" to set theClipboard to the clipboard
set saveD to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set tempList to every text item of theClipboard
set theImportList to {}
repeat with lineItem in tempList
set AppleScript's text item delimiters to {" - "}
copy every text item of lineItem to end of theImportList
end repeat
set AppleScript's text item delimiters to saveD

tell application "iTunes"
-- create a new playlist
make new user playlist with properties {name:"Disco XT playlist"}
set newPlaylist to playlist "Disco XT playlist"
set the view of the front browser window to newPlaylist

-- add tracks to new playlist
repeat with trackItem in theImportList
set copy_these to (get every track of library playlist 1 whose artist is (first item of trackItem) and name is (second item of trackItem))
repeat with thisTrack in copy_these
duplicate thisTrack to newPlaylist
end repeat
end repeat
end tell


No comments:

Post a Comment