FROM : Adam P Jenkins
DATE : Mon Mar 03 00:40:54 2008
On Mar 2, 2008, at 6:16 PM, Adam P Jenkins wrote:
> Just call the "get" method on the track object that currentTrack
> returns to get the iTunesFileTrack object. I.e. this works
>
> iTunesFileTrack *currentTrack = [[iTunes currentTrack] get];
> NSLog("location is %@", currentTrack.location);
>
> The documentation for the "get" method from the SBObject.h header is:
>
> // Evaluate the object by sending it to the target application.
> Depending on what
> // the object points to, the result may be a Foundation object such
> as an NSString
> // (for most properties), an NSAppleEventDescriptor (for properties
> of a type with
> // no Foundation equivalent), or another SBObject (for most
> elements).
>
> Another example of where you need to use it in the iTunes SB
> interface is when accessing iTunes.selection property, which returns
> an SBObject, but then if you call "get" on it, you get an NSCFArray
> of tracks, which is what you wanted in the first place. I'm not
> sure what the logic is behind the "get" method, but there it is.
I just read the detailed and very informative post that "has" just
posted about AppleScript's event semantics and scripting bridge, and
now I understand what the "get" method is for and why it needs to be
called. This also made me realize that what I posted above isn't
really safe since currentTrack won't always be a iTunesFileTrack. So
really you'd want something like:
iTunesTrack *currentTrack = [iTunes.currentTrack get];
if ([currentTrack isKindOfClass:[iTunesFileTrack class]]) {
iTunesFileTrack *fileTrack = (iTunesFileTrack*)currentTrack;
NSLog("location = %@", fileTrack.location);
}
DATE : Mon Mar 03 00:40:54 2008
On Mar 2, 2008, at 6:16 PM, Adam P Jenkins wrote:
> Just call the "get" method on the track object that currentTrack
> returns to get the iTunesFileTrack object. I.e. this works
>
> iTunesFileTrack *currentTrack = [[iTunes currentTrack] get];
> NSLog("location is %@", currentTrack.location);
>
> The documentation for the "get" method from the SBObject.h header is:
>
> // Evaluate the object by sending it to the target application.
> Depending on what
> // the object points to, the result may be a Foundation object such
> as an NSString
> // (for most properties), an NSAppleEventDescriptor (for properties
> of a type with
> // no Foundation equivalent), or another SBObject (for most
> elements).
>
> Another example of where you need to use it in the iTunes SB
> interface is when accessing iTunes.selection property, which returns
> an SBObject, but then if you call "get" on it, you get an NSCFArray
> of tracks, which is what you wanted in the first place. I'm not
> sure what the logic is behind the "get" method, but there it is.
I just read the detailed and very informative post that "has" just
posted about AppleScript's event semantics and scripting bridge, and
now I understand what the "get" method is for and why it needs to be
called. This also made me realize that what I posted above isn't
really safe since currentTrack won't always be a iTunesFileTrack. So
really you'd want something like:
iTunesTrack *currentTrack = [iTunes.currentTrack get];
if ([currentTrack isKindOfClass:[iTunesFileTrack class]]) {
iTunesFileTrack *fileTrack = (iTunesFileTrack*)currentTrack;
NSLog("location = %@", fileTrack.location);
}
| 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

