FROM : Christopher Nebel
DATE : Mon Mar 03 21:22:33 2008
On Mar 1, 2008, at 5:28 PM, Hannes Petri wrote:
> I want to retrieve the path to the currently played file in iTunes.
> I thought scripting bridge would be the perfect tool for this,
> however i've run into some problem. I have this code:
>
> iTunesApplication *iTunes = [[SBApplication alloc]
> initWithBundleIdentifier:@"com.apple.iTunes"];
> iTunesTrack *currentTrack = [iTunes currentTrack];
>
> if ([currentTrack isKindOfClass:[iTunesFileTrack class]]) {
> …
> }
>
> The problem is, that the class of the object returned is _always_
> iTunesTrack, and not iTunesFileTrack, as i expect it to be.
As described in the Scripting Bridge Release Note under Lazy
Evaluation (using precisely this as an example, no less), SBObjects
are not evaluated until you either try to get some concrete data from
them (e.g., "name"), or until you invoke -get. "currentTrack" is
nothing more or less than a reference to "the current track in
iTunes". If you want to find out precisely what it is *now*, do this:
iTunesTrack *currentTrack = [[iTunes currentTrack] get];
-isKindOfClass: will then give you the answer you seek.
--Chris Nebel
AppleScript Engineering
DATE : Mon Mar 03 21:22:33 2008
On Mar 1, 2008, at 5:28 PM, Hannes Petri wrote:
> I want to retrieve the path to the currently played file in iTunes.
> I thought scripting bridge would be the perfect tool for this,
> however i've run into some problem. I have this code:
>
> iTunesApplication *iTunes = [[SBApplication alloc]
> initWithBundleIdentifier:@"com.apple.iTunes"];
> iTunesTrack *currentTrack = [iTunes currentTrack];
>
> if ([currentTrack isKindOfClass:[iTunesFileTrack class]]) {
> …
> }
>
> The problem is, that the class of the object returned is _always_
> iTunesTrack, and not iTunesFileTrack, as i expect it to be.
As described in the Scripting Bridge Release Note under Lazy
Evaluation (using precisely this as an example, no less), SBObjects
are not evaluated until you either try to get some concrete data from
them (e.g., "name"), or until you invoke -get. "currentTrack" is
nothing more or less than a reference to "the current track in
iTunes". If you want to find out precisely what it is *now*, do this:
iTunesTrack *currentTrack = [[iTunes currentTrack] get];
-isKindOfClass: will then give you the answer you seek.
--Chris Nebel
AppleScript Engineering
| Related mails | Author | Date |
|---|---|---|
| Hannes Petri | Mar 2, 02:28 | |
| Jonathan 'Wolf' Re… | Mar 2, 06:06 | |
| has | Mar 2, 13:05 | |
| Steven Degutis | Mar 2, 13:54 | |
| has | Mar 3, 00:02 | |
| Adam P Jenkins | Mar 3, 00:16 | |
| Adam P Jenkins | Mar 3, 00:40 | |
| has | Mar 3, 01:44 | |
| Jens Alfke | Mar 3, 07:32 | |
| has | Mar 3, 16:21 | |
| Steven Degutis | Mar 3, 16:27 | |
| Christopher Nebel | Mar 3, 21:22 | |
| has | Mar 3, 22:45 |






Cocoa mail archive

