Accessing iTunes DB through Applescript?

Member
Posts: 196
Joined: 2003.10
Post: #1
I know this may/may not be game-related, but iDG has a larger community than iDA, and it's not inconceivable that someone might use this code in a game.

What I want to do is use Applescript to get a list of playlists from iTunes. I don't want to read the xml version of the library - I want a realtime list of playlists (as far as I understand it the xml is only revised on quit - I'd like changes made in iTunes to show up in my application).

Thing is, and I've googled this a ton, I can't for the life of me figure out how on earth to do this. I've pored over the applescript dictionary, looking at open source code - I just don't get it. This seems like a fairly simple thing to do - can someone give me a hand here? Thanks in advance.
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #2
This is pretty basic and may be a little buggy. Plus my Script Editor app won't seem to run right now so I can't just copy and paste. Hopefully it works though Smile.

Code:
set song_counter to 1

tell application "iTunes"
     repeat while(song_counter <= (number of tracks of library playlist 1))
          set song_name to name of (track song_counter of library playlist 1)
          -- then repeat for other information and do what you will with it
     end tell
end tell

I'm sorry if there's an error, but I had a similar script running moments ago before my computer froze. Now it refuses to open that script. I'm assuming the file got corrupted because I can open and run other scripts. I'm also not the über-scripter, so you may want to double check to make sure you won't be getting errors with it.
Quote this message in a reply
Member
Posts: 196
Joined: 2003.10
Post: #3
Great - this is a good start. As far as I understand it this code iterates through each track of the users library.

Now how would I tackle this for playlists?
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Creating a window and accessing OpenGl using C++ RagingAvatar 5 4,327 Nov 5, 2009 10:37 AM
Last Post: OneSadCookie
  Accessing c++ class from Obj-C .h file dsedov 3 3,801 Jul 1, 2009 11:07 PM
Last Post: dsedov
  iTunes 8 Visualizer Talyn 3 2,430 Oct 7, 2008 09:50 PM
Last Post: maximile
  Applescript/shellscript Byron Clarke 3 2,759 Jul 26, 2005 02:16 AM
Last Post: Andrew