Re: removing an item from a list [Was: Two Questions]
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