• 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: removing an item from a list [Was: Two Questions]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: removing an item from a list [Was: Two Questions]


  • Subject: Re: removing an item from a list [Was: Two Questions]
  • From: email@hidden
  • Date: Sun, 11 Feb 2001 23:21:41 EST

Here's my (battle tested) handler for this situation (very similar to Marc's,
but accounts for out of range requests):

on purgeFromList(theList, indexOfThePurged)
copy theList to newlist
try
set x to indexOfThePurged
if x < 1 then return theList
set coitl to count of items in theList
if x > coitl then return theList
if x = coitl then
set newlist to (items 1 thru -2 of theList)
else
set newlist to (items 1 thru (x - 1) of theList) & (items (x + 1)
thru -1 of theList)
end if
on error
copy theList to newlist
end try
return newlist
end purgeFromList

Note that many other scripting languages like Perl and Javascript consider
the first item of a list to be item 0, and the last item of the list is at
position (length of list-1).

In the interest of promoting object oriented design and library building, may
I suggest that answers be given in the form of a handler if the responder has
one that is tested and stable?

Jeff Baumann
email@hidden
www.linkedresources.com

History is interesting. An apple fell on Newton's head and he invented
Calculus, while Bill Gates invented Windows and got a pie in the face.


In a message dated 2/11/01 2:25:13 PM, you wrote:

>Message: 14
>Date: Sun, 11 Feb 2001 13:13:05 -0700
>Subject: Two Questions
>From: Byron Peterson <email@hidden>
>To: <email@hidden>
>
>Hello,
>
>I have two questions.
>
>First:
>
>What is the fastest way to remove an item from a large list (the list I9m
>working with has about 3000 items in it). The item I need to remove is in
>the middle of the list and it isn9t the same item every time?
>
>Second:
>
>Is there anyway to change the desktop picture via an applescript without
>opening the Appearance Control Panel?
>
>Thanks,
>
>Byron Peterson


  • Prev by Date: Re: making new documents with Style
  • Next by Date: Starting up the Computer
  • Previous by thread: Re: removing an item from a list [Was: Two Questions]
  • Next by thread: Simple question: List Folder
  • Index(es):
    • Date
    • Thread