• 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: Slow script with long lists
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Slow script with long lists


  • Subject: Re: Slow script with long lists
  • From: Matt Deatherage <email@hidden>
  • Date: Tue, 18 Oct 2005 23:53:34 -0500

On 10/18/05 at 10:42 PM, Chris Mahn <email@hidden> wrote:

> The script below achieves this goal, although it does it very very
> slowly when the list is only moderately long (>300 songs). I shudder to
> think of it working on 20,000 songs.

Friends don't let friends do this kind of thing to lists.  For a list of 300 songs, you're forcing AppleScript to find an item inside that list about 300 times, by copying 299 items and when setting "this_item" to "item i of trk_list".  And then more for writing, and, oh, it just makes the head hurt.  You're lucky it finishes at all.

To remove item "i" from your list, try this:

> set dummyList to {}
> set i to 55
> set dummyList to ((items 1 thru (i - 1) of trk_list) as list) ¬
>     & (items (i + 1) thru -1 of trk_list) as list

This lets AppleScript create a list of items 1 through i-1, and another list of items i+1 through the end, and then concatenates them in one easy operation, instead of concatenating a new item to a list 300 times.  On my system, this takes less than a second for a 4671-item list.  The original takes a very long time.

You have to put parentheses around the (i+1) and (i-1) or AppleScript can't parse what you mean.  There's probably a shorter way to say the same thing, but my syntax module is unloaded from my brain right now.

By the way, this line:

>       set trk_list to get index of every track of library playlist 1

..just produces a list of hundreds of items whose initial contents are the same as their indexes.  Item 1 is the number "1", item 2 is "2", and item 4671 is "4671".  I can see where you might want to do it for keeping track of every song in a random order, but if not, there have to be ways to do it without the overhead of 20,000-item lists.

--Matt

--
Matt Deatherage                              <email@hidden>
GCSF, Incorporated                      <http://www.macjournals.com>

Cheaters only prosper in Mario Kart.

Now Playing "Fifth Symphony: Moderatly and Sustained; Allegro Assai" by Otonowa Wind Symphonica, Alfred Reed, from "Alfred Reed Live! Volume 3: Giligia"
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Slow script with long lists
      • From: Chris Mahn <email@hidden>
    • Re: Slow script with long lists
      • From: Bastiaan Boertien <email@hidden>
References: 
 >Slow script with long lists (From: Chris Mahn <email@hidden>)

  • Prev by Date: Slow script with long lists
  • Next by Date: Re: Getting a handler to use a value from a different handler?
  • Previous by thread: Slow script with long lists
  • Next by thread: Re: Slow script with long lists
  • Index(es):
    • Date
    • Thread