• 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 items from lists
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Removing items from lists


  • Subject: Re: Removing items from lists
  • From: Paul Berkowitz <email@hidden>
  • Date: Sun, 06 Oct 2002 08:17:41 -0700

On 10/6/02 7:16 AM, "Goldfish" <email@hidden> wrote:

> What would be the correct syntax for removing an item from a list?
>
> e.g. set x to every item of {"the","quick","brown","fox"} except "quick"
>
> Any ideas?

There is no command to do it in AppleScript. (In an AppleScript Studio
document, I read "There is no command in AppleScript to remove list items
YET." Interesting, no?) You have to run a repeat loop. This handler gives
the idea. It's been generalized so you can exclude more than one item. If
you have only one item, put it in list brackets first. I.e.

set theList to {"the","quick","brown","fox"}
set exclItems to {"quick"}
set theList to my RemoveListItems(theList, exclItems)


to RemoveListItems(theList, exclItems) -- both lists

local tempList, theItem

set tempList to {}

repeat with i from 1 to (count theList)
set theItem to item i of theList
if {theItem} is not in exclItems then
set end of tempList to theItem
end if
end repeat

return tempList

end RemoveListItems


For reasons we can go into another time, if the main list theList is a large
list, over 100 items or so, it really pays to use the following version
incorporating a script object. it goes much faster. When your list is 1000
items or larger, it can be hundreds or thousands of times faster - a second
or so rather than minutes. Method thanks to Serge Belleudy-d'Espinose:

to RemoveListItems(theList, exclItems) -- both lists

local tempList, theItem

set tempList to {}

script listScript
property listRef : theList
end script

repeat with i from 1 to (count theList)
set theItem to item i of listScript's listRef
if {theItem} is not in exclItems then
set end of tempList to theItem
end if
end repeat

return tempList

end RemoveListItems





--
Paul Berkowitz
_______________________________________________
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.

References: 
 >Removing items from lists (From: Goldfish <email@hidden>)

  • Prev by Date: Re: Removing items from lists
  • Next by Date: OT Address Book Rant
  • Previous by thread: Re: Removing items from lists
  • Next by thread: Re: Removing items from lists
  • Index(es):
    • Date
    • Thread