Skip navigation.
 
mlRe: Problems with ScriptingBridge and iTunes
FROM : Adam P Jenkins
DATE : Mon Mar 03 00:16:30 2008

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.

Adam

On Mar 1, 2008, at 8:28 PM, Hannes Petri wrote:

> Hello!
>
> 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. If i run 
> the following applescript code:
>
> tell application "iTunes" to current track
>
> I get a "file track", which makes it possible to fetch the path 
> using the "location" attribute. If I, in the ObjC example, try 
> [currentTrack location], I'm told that it doesn't respond to that 
> selector.
> I have made certain that the object is of class iTunesTrack by 
> typing 'po [currentTrack class]' in gdb.
>
> Very thankful for help!
>
>
> Hannes Petri_______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>

Related mailsAuthorDate
mlProblems with ScriptingBridge and iTunes Hannes Petri Mar 2, 02:28
mlRe: Problems with ScriptingBridge and iTunes Jonathan 'Wolf' Re… Mar 2, 06:06
mlRe: Problems with ScriptingBridge and iTunes has Mar 2, 13:05
mlRe: Problems with ScriptingBridge and iTunes Steven Degutis Mar 2, 13:54
mlRe: Problems with ScriptingBridge and iTunes has Mar 3, 00:02
mlRe: Problems with ScriptingBridge and iTunes Adam P Jenkins Mar 3, 00:16
mlRe: Problems with ScriptingBridge and iTunes Adam P Jenkins Mar 3, 00:40
mlRe: Problems with ScriptingBridge and iTunes has Mar 3, 01:44
mlRe: Problems with ScriptingBridge and iTunes Jens Alfke Mar 3, 07:32
mlRe: Problems with ScriptingBridge and iTunes has Mar 3, 16:21
mlRe: Problems with ScriptingBridge and iTunes Steven Degutis Mar 3, 16:27
mlRe: Problems with ScriptingBridge and iTunes Christopher Nebel Mar 3, 21:22
mlRe: Problems with ScriptingBridge and iTunes has Mar 3, 22:45