• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: No track index in iTunes SB?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: No track index in iTunes SB?


  • Subject: Re: No track index in iTunes SB?
  • From: has <email@hidden>
  • Date: Tue, 11 Mar 2008 00:47:42 +0000

Adam P Jenkins wrote:

Anyone know how to get the index of the current iTunes track using
Scripting Bridge?

You'll have to muck about with raw AE codes if you want to do it with Scripting Bridge; see past discussions of SB's design flaws for more info.

Actually it's doable in scripting bridge, without any codes. [...] Instead of calling indexOfObjects:, try something like:

    int index = -1;
    int i;

    for (i = 0; i < [currentTracks count]; i++) {
        if ([[currentTracks objectAtIndex:i] id] == [currentTrack
id]) {
            index = i + 1;
            break;
        }
    }
    // now index is either the index of the track, or -1


Bah, philistine. Try this sort of thing on a 100,000 item playlist when track 99,999 is playing. Don't worry, I'll wait...

Seriously tho', if you really have to resort to this sort of crude iterative approach, you're often best to get all property values at once (-arrayByApplyingSelector: in SB's addlepated API) and then iterate over (or, in this case, use -indexOfObject:) the resulting NSArray to locate the item you want. At least then you'll minimise the number of Apple events that actually have to be sent (one to get the current track's id, one to get a list of ids for every track in the playlist). For all SB's pseudo-OO appearance it's still Apple event IPC underneath, with all the latency issues that entails. And while hardware and software improvements have gone a long way to ameliorating the cost of sending interprocess messages, they're still much more expensive than local method calls.

Personally, I'll stick with doing thing the AppleScript way [1] - for all the problems with the Apple Event Object Model, it's wonderfully elegant and concise when it does work. Then again, I'm old-school, and these days even I can't help feeling that Apple should just retire the AEOM as too complex for its own good, and go for a dumb and crude, but simple and reliable, IPC approach more along the lines of DO or COM.

has

[1] Albeit using appscript; I've long since had my fill of the AppleScript language itself.
--
Control AppleScriptable applications
from Python, Ruby and ObjC:
http://appscript.sourceforge.net


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: No track index in iTunes SB?
      • From: Adam P Jenkins <email@hidden>
  • Prev by Date: Re: [Moderator] iPhone discussion here - RETRACTION
  • Next by Date: Re: [iPhone] xml parsing
  • Previous by thread: Re: No track index in iTunes SB?
  • Next by thread: Re: No track index in iTunes SB?
  • Index(es):
    • Date
    • Thread