Re: Get iTune File Track by Alias
Re: Get iTune File Track by Alias
- Subject: Re: Get iTune File Track by Alias
- From: <email@hidden>
- Date: Tue, 20 Apr 2004 08:42:06 -0700 (PDT)
>
Date: Thu, 15 Apr 2004 16:24:24 +0100
>
Subject: Re: Get iTune File Track by Alias
>
From: Nigel Smith <email@hidden>
>
To: Applescript Users List <email@hidden>
>
>
On 15/4/04 5:15, "Michael Terry" <email@hidden> wrote:
>
>
> Yes, what you tried should have worked. None of the alternatives I
>
> thought of are very fun or fast. This is the best I could come up with:
>
>
How about using a binary search? I don't know how fast this is for a lot of
>
tracks -- I don't have many in iTunes, myself...
>
>
----------
>
tell application "iTunes"
>
set testFile to location of file track 15 of playlist "Library"
>
set theList to location of every file track of playlist "Library"
>
if theList contains testFile then
>
set trackNum to binSearch(testFile, theList, 1) of me
>
return file track trackNum of playlist "Library"
>
end if
>
end tell
>
>
on binSearch(aTerm, aList, aNumber)
>
if (count of aList) = 1 then
>
return aNumber
>
else
>
set midItem to (((count of aList) / 2) as integer)
>
copy items 1 thru midItem of aList to tmp
>
if tmp contains aTerm then
>
binSearch(aTerm, tmp, aNumber)
>
else
>
binSearch(aTerm, items (midItem + 1) thru -1 of aList, <line-break>
>
aNumber + midItem)
>
end if
>
end if
>
end binSearch
But, for this to work, doesn't it assume that 'location of every file track of
playlist "Library"' will be alphabetically sorted? Is that really a safe
assumption? I thought songs were listed in the library in the order you added
them so they could very quickly become listed out of order.
-jdr
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.