Subscribe to
Posts
Comments
NSLog(); Header Image

Cocoa Query: Give Me Only Checked iTunes Songs

The XML file iTunes produces has one fatal flaw: it doesn't tell you which song is checked and which is not. Unfortunately, Brad and I need to get the "checked or not" information as well. Does anyone know the fastest and/or "best" way to do so?

P.S. We're doing the parsing in straight C, currently, but would take a solution via any compatible language or method.

10 Responses to "Cocoa Query: Give Me Only Checked iTunes Songs"

  1. It's not even close to C, but if you look at the iTunes Dictionary, there's an "enabled" property for the track class:

    enabled (boolean) : is this track checked for playback?

    I'm not *sure* that this is the same as checked in iTunes, but, it wouldn't be hard to check and see if it is. It may be a good starting point to look.

  2. [quote comment="45079"]enabled (boolean) : is this track checked for playback?[/quote]

    Yeah, 10,000 AppleScript calls probably won't work for us. 🙂 I know it's in the dictionary… I'm just hoping it's exposed elsewhere. It's probably in the "iTunes Library" file, of course.

  3. well, you wouldn't have to do it via AppleScript per se, although I imagine the raw event calls wouldn't be a great way to do it either. What precisely are you doing when you need the info?

  4. I think you could do it quickly with one AppleScript call:

    get id of every track whose enabled is true

  5. Good point Michael. I think it's easy to get into the "must make a hundred individual calls" mindset with AppleScript, because with other languages, the penalty you pay for this is smaller. (Small brag moment: I ended up helping Bruce Horn out with a similar issue for a project he was working on.) With AppleScript, or even the underlying events, there's a point, and you reach it pretty quick, where you're better off asking once for a lot of data, than a thousand times for a little data.

  6. [quote comment="45081"]well, you wouldn't have to do it via AppleScript per se, although I imagine the raw event calls wouldn't be a great way to do it either. What precisely are you doing when you need the info?[/quote]

    Yeah, my limited testing with AS-in-Cocoa is that it's slow regardless of the methods used.

    [quote comment="45082"]get id of every track whose enabled is true[/quote]

    That appears to work. On 11,137 tracks, this script:

    tell application "iTunes"
        set timeStamps to "Start: " & (current date) & return
        set allTracks to id of every track in user playlist id 25572 whose enabled is true
        set timeStamps to timeStamps & "End:   " & (current date)
        return timeStamps
    end tell

    Generates this output:

    Start: Friday, December 28, 2007 12:51:05 pm
    End:   Friday, December 28, 2007 12:51:05 pm

    So… yeah, that might work after all. I still have to wonder if there's not a solution that won't require creating a table/dictionary/database of songs, another for enabled tracks, then running through the latter to prune the former.

    But at least the AS method isn't as slow as I thought. Thanks!

  7. You can also get a bit of a speed boost (and avoid nasty NSApplescript and AS syntax) by using the scripting bridge, although at the cost of 10.4 support.

  8. [quote comment="45088"]You can also get a bit of a speed boost (and avoid nasty NSApplescript and AS syntax) by using the scripting bridge, although at the cost of 10.4 support.[/quote]

    We're not too worried about 10.4 support, I don't believe.

    One other thing: iTunes must be running for this AppleScript solution to work. Other solutions seem to get the "checked" status without launching iTunes (or requiring iTunes to be running).

  9. Found it. What you have to look for is the presence of a "Disabled" key which will have a value of true. If the track is checked, the disabled key isn't there. If the track is NOT checked, then it's there.

  10. [quote comment="45125"]Found it. What you have to look for is the presence of a "Disabled" key which will have a value of true. If the track is checked, the disabled key isn't there. If the track is NOT checked, then it's there.[/quote]

    That seems to be right. Thanks! I'm not sure how I missed that earlier. 😛


Comments RSS

Leave a Reply


Warning: Undefined variable $user_ID in /var/www/vhosts/nslog.com/httpsdocs/wp-content/themes/nslog/comments.php on line 96

Please abide by the comment policy. Valid HTML includes: <blockquote><p>, <em>, <strong>, <ul>, <ol>, and <a href>. Please use the "Quote Me" functionality to quote comments.