how ???
i accidently posted the first one over someones no sure how but sorry.
Hi,
I think when I did this before it was longer or maybe it was removing something from a string. You can check it out if anything is missing:
set the_list to {1, 2, 3}
set the_item to 2
if the_item is not in the_list then return the_list
set the_count to (count the_list)
repeat with i from 1 to the_count
set this_item to (item i of the_list)
if this_item is the_item then
exit repeat
end if
end repeat
tell the_list
if i = 1 then
set new_list to rest
else if i = the_count then
set new_list to reverse of rest of reverse
else
set new_list to (items 1 thru (i - 1)) & (items (i + 1) thru -1)
end if
end tell
gl,
this doesnt work… it just doesnt do anything
set the_list to contents of default entry "existingfolders" of user defaults as list
set the_item to the_folder_name
set the_count to (count the_list)
repeat with i from 1 to the_count
set this_item to (item i of the_list)
if this_item is the_item then
exit repeat
end if
end repeat
tell the_list
if i = 1 then
set new_list to rest
else if i = the_count then
set new_list to reverse of rest of reverse
else
set new_list to (items 1 thru (i - 1)) & (items (i + 1) thru -1)
end if
end tell
set the_list to new_list
tell window "main"
tell menu of popup button "Delete"
delete menu items
set current_item to 1
set num_of_items to count of items of the_list
repeat --with the_item in the_list
if current_item is equal to (num_of_items + 1) then
exit repeat
else
set the_item to (text item current_item of (contents of the_list))
make new menu item at end of menu items with properties {title:the_item}
set current_item to (current_item + 1)
end if
end repeat
end tell
tell menu of popup button "Open"
delete menu items
set current_item to 1
set num_of_items to count of items of the_list
repeat
if current_item is equal to (num_of_items + 1) then
exit repeat
else
set the_item to (text item current_item of (contents of the_list))
make new menu item at end of menu items with properties {title:the_item}
set current_item to (current_item + 1)
end if
end repeat
end tell
end tell
there’s got to be a simpler way to remove an item from a list…
I’m not really following the scripts that have been posted (this site has it’s text set too small especially for script and the IE I must use can’t enlarge it, so it’s difficult for me to read, old man that I am), but as far as removing an item from a list, would the script/subroutine below be what you’re asking for?
set testList to {"Alpha", "Beta", "Gamma", "Omega"}
set testList to removeListItemMatch(testList, "Gamma")
on removeListItemMatch(thisList, matchItem)
set newList to {}
repeat with i from 1 to count of thisList
set thisItem to item i of thisList
if thisItem does not equal matchItem then copy thisItem to the end of newList
end repeat
return newList
end removeListItemMatch
Hi,
In these lines:
set the_list to contents of default entry “existingfolders” of user defaults as list
set the_item to the_folder_name
I don’t know waht these things are “default entry”, user defaults, but they look familiar. When you compare an item of the_list to the_item are they the same type of item? Are they both strings? The list may contain references, I don’t know. Otherwise, you’ll never get a match.
If that’s not it, then in this line:
set this_item to (item i of the_list)
try this:
set this_item to (contents of (item i of the_list))
Sometimes (I don’t know exactly when), you get a reference to the item. Then when you compare you’re comparing an item to the reference to a list item and not the value. Usually this happens with the repeat variable, but I’m not doing that here.
Here, I used the Finder to get a list of folder names:
set the_folder to (choose folder)
tell application “Finder”
set the_list to (name of every folder of the_folder)
end tell
set the_item to (item 1 of the_list) – remove the first item, change 1 to get another name
set the_count to (count the_list)
repeat with i from 1 to the_count
set this_item to (item i of the_list)
if this_item is the_item then
exit repeat
end if
end repeat
tell the_list
if i = 1 then
set new_list to rest
else if i = the_count then
set new_list to reverse of rest of reverse
else
set new_list to (items 1 thru (i - 1)) & (items (i + 1) thru -1)
end if
end tell
{the_list, new_list}
gl,