Question

I am new to Objective-C. I am now trying to get song information of selected track. But I can't.

I've found that following code

iTunesFileTrack *cuTrack = [iTunesApp.currentTrack get];
NSLog(@"result = %@",cuTrack);

outputs reference(?) of current track. Like:

2014-01-21 00:07:09.908 CommunicateWithiTunes[43052:303] result = <ITunesFileTrack @0x60800005de20: ITunesFileTrack id 12825 of ITunesUserPlaylist id 12773 of ITunesSource id 74 of application "iTunes" (166)>

so it can be re-usable like:

NSLog(@"name = %@", cuTrack.name);
NSLog(@"location = %@", cuTrack.location);

But if I re-write code as selection like:

iTunesFileTrack *selectedTrack = [iTunesApp.selection get];
NSLog(@"result = %@",selectedTrack);

outputs text(?) of selected track like:

2014-01-21 00:15:40.753 CommunicateWithiTunes[43145:303] result = (
 "<ITunesFileTrack @0x61000044fe70: ITunesFileTrack id 12825 of ITunesUserPlaylist id 12773 of ITunesSource id 74 of application \"iTunes\" (166)>"

so the result can't be re-usable.

Why this kind of difference occur? Or Can anyone tell me the correct way to get information of selected track?

Was it helpful?

Solution

The selection is always an array (just like in AppleScript). Now just cycle through the items of the array. In your example there is only one. That is what the parentheses in your console log output are telling you: your second result is an array consisting of one item which is a reference to a file track, which itself is identical to your first result.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top