My aim is to eliminate each item, one at a time, and represent the remaining ones until no more remain.
This works however I have thousands of items in the list and it is slow.
Is there a way to get the position of the item (its number in the list) and then just delete that item?
That would make it so much faster.
Thanks.
set myList to {"a", "b", "c", "d"}
set myParsedList to {}
repeat while myList is not {}
set usrChc to (choose from list myList with prompt "Delete from list" OK button name "Delete")
if usrChc is false then return -- user cancelled
repeat with thisItem in myList
if (thisItem as text) is not (usrChc as text) then set end of myParsedList to thisItem
end repeat
set myList to myParsedList
set myParsedList to {}
end repeat
Perhaps
set mylist to {"able", "baker", "charlie", "delta", "baker", "able"}
set tid to AppleScript's text item delimiters
repeat while mylist is not {}
set usrChc to (choose from list mylist with prompt "Delete from list" OK button name "Delete")
if usrChc is false then -- user cancelled
set AppleScript's text item delimiters to tid
return
end if
set AppleScript's text item delimiters to {ASCII character 5}
set myString to mylist as string
set AppleScript's text item delimiters to {usrChc & (ASCII character 5)}
set mylist to text items of myString
set AppleScript's text item delimiters to {""}
set myString to mylist as string
set AppleScript's text item delimiters to {ASCII character 5}
set mylist to text items of myString
end repeat
set AppleScript's text item delimiters to tid
This is a bit clunkier, but more robust
set tid to AppleScript's text item delimiters
set myList to {"a", "abe", "a", "b", "a", "alice", "a"}
repeat while myList is not {}
set usrChc to (choose from list myList with prompt "Delete from list" OK button name "Delete")
if usrChc is false then -- user cancelled
set AppleScript's text item delimiters to tid
return
end if
set myDelimiter to ASCII character 5
set myOtherDelimiter to ASCII character 11
set myDelimiter2 to myDelimiter & myDelimiter
set myotherDelimiter2 to myOtherDelimiter & myOtherDelimiter
set AppleScript's text item delimiters to {myOtherDelimiter & myDelimiter2 & myOtherDelimiter}
set mystring to myOtherDelimiter & (myList as string) & myOtherDelimiter
set AppleScript's text item delimiters to {myOtherDelimiter & usrChc & myOtherDelimiter}
set myList to text items of mystring
set AppleScript's text item delimiters to {""}
set mystring to myList as string
repeat until not (mystring contains myDelimiter)
set AppleScript's text item delimiters to {myDelimiter}
set myList to text items of mystring
set AppleScript's text item delimiters to {""}
set mystring to myList as string
end repeat
try
set mystring to characters 2 thru -2 of mystring as string
end try
set AppleScript's text item delimiters to {myotherDelimiter2}
set myList to text items of mystring
end repeat
set AppleScript's text item delimiters to tid
Thanks mikerickson,
I tested and I am sorry to report that with 29456 files in the list it still takes too much time.
I was hoping that you would be able to get the item number of the choice in the list so that you could simply say delete item itmNr and be done with it.
I am now working on cutting down the list into smaller lists (up to 2000 items it is not so bad) and presenting them one at a time until they are all empty.
The fastest way I know of to traverse a list is with something called a script object. Here’s is a link to what they are.
http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/conceptual/ASLR_script_objects.html
I can’t explain exactly why they’re faster but they are tremendously faster when working with large lists. The idea is to put your large list into a property of a script object, and then use that object to work with your list. You’ll be amazed at the speed gain. Give it a try with your large list and see how much faster it is! Here’s an example of what to do.
set mylist to {"able", "baker", "charlie", "delta", "baker", "able"}
set itemToRemove to "baker"
-- define the script object
script s
property scriptList : null
property finalList : {}
end script
-- set your large list to a property in the script object
set s's scriptList to mylist
-- create the new list in another property of the script object
repeat with i from 1 to count of s's scriptList
if item i of s's scriptList is not equal to itemToRemove then set end of s's finalList to item i of s's scriptList
end repeat
return s's finalList
I don’t have a file to test that extensivly, was my posted script faster than the looping script?
Regulus, thanks for the link to script objects, it looks powerful.