views:

21

answers:

2

Hello,

I'm trying since one month to create an application that detects the current track of iTunes to tag the song and calculate the bpm (through a taping button)

When the user modifies one of the field of the tag, the track is locked in the application : that means : if iTunes currentTrack changes, my application stay on the previous track.

My problem : I've got the persistent ID of the previous track. I created an applescript to get the track corresponding to this persistent ID. But I don't find how to get this track in cocoa part of the application !!!!

here the script :

on open param
    tell application "iTunes"
        set trackItems to (every track of playlist "Library" whose persistent ID is param)
        repeat with aTrack in trackItems
            return aTrack
        end repeat
        return null
    end tell
end open

On cocoa side,

NSAppleEventDescriptor *desc = [findTrackWithPersistentIDScript runWithParameters: [NSArray arrayWithObjects: lockPersistentID ,nil]];

what can i do with the NSAppleEventDescriptor ? I would like to have a iTunesTrack or iTunesFileTrack . I verify with a display dialog that the track is well found

Thanks for reading and for your help !

PS : when i debug, if i do [ desc data ] , i have a NSContreteData and below an iTunesItem. But I don't know how to get this iTunesItem (i tried a cast...) and i managed to get it, what can i do with it to have an iTunesTrack .

A: 

It's easy to convert strings back and forth between applescript and obj-c. So my sugestion would be to pass only strings back and forth. For example, you can't really do anything with "the track" in cocoa, so don't pass that back because you don't really need it anyway. Pass back the track name instead. Or pass back the persistent id as text. Or pass back "true" meaning you found it or "false" meaning you couldn't find it.

Then in cocoa to get the NSString of the applescript result just use [result stringValue].

regulus6633
A: 

Thanks for your answer. The problem is that if I return the persistentID as string, i'm not able to get the track in cocoa from its persistent ID. Do you know how to do this ? I didn't find anything to do this (but very easy in appelscript).

Remark : i use a script to get the persistent ID of a track because in cocoa, when i do :

[ [ iTunes currentTrack ] persistentID ] 

i get something very different and smaller that the true persistent ID, i don't know what it represents exactly.

laurent