set foo to {"bread", "milk", "butter", "eggs"}
set item_num to my list_position("milk", foo)
on list_position(this_item, this_list)
repeat with i from 1 to the count of this_list
if item i of this_list is this_item then return i
end repeat
return 0
end list_position
I found this little beauty by Emmanuel Levy some months later hidden in this thread. This one should prove a lot faster, but not tested.
on indexof(theItem, theList) -- credits Emmanuel Levy
set text item delimiters to return
set theList to return & theList & return
set text item delimiters to {""}
try
-1 + (count (paragraphs of (text 1 thru (offset of (return & theItem & return) in theList) of theList)))
on error
0
end try
end indexof
I feel that it would be safer to edit it this way :
on indexof(theItem, theList) -- credits Emmanuel Levy
set oTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set theList to return & theList & return
set AppleScript's text item delimiters to oTIDs
try
-1 + (count (paragraphs of (text 1 thru (offset of (return & theItem & return) in theList) of theList)))
on error
0
end try
end indexof
After all,the in use delimiters may be different than {“”}
Yvan KOENIG (VALLAURIS, France) dimanche 4 juillet 2010 12:14:00
Stefan pointed out for me the other day, that you don’t have to use AppleScript’s text item delimiters when you have an application in its scope. (No surrounding tell block).
-I’m living in the belief that these text item delimiters is local to the block they are used.
It is very timely with info on this, because I have a beast for you guys hopefully today, I’m working on the last buggy behavior. Edit: It is a beast internally, but is really easy to use from your code, and doesn’t obstract your code’s logic much, considering the useful things it does. It was made to give your scripts added functionality transparently to your original code. I shall say no more but Try it! when I have uploaded it to Code Exchange. It comes with a fully working Demo.
I received nothing.
I learnt this morning that my provider had some problems in the period 2010/07/01 . 2010/07/03
A friend trieng to send me a mail deceived :
: delivery temporarily suspended: host smtp-in.sfr.fr[93.17.128.7] refused to talk to me: 421 4.7.0 msfrf2102.sfr.fr Error: too many connections from 80.12.242.144
At this time it seems to be OK.
I may bve rude but I’m polite enough to respond when some one send me a mail (mainly when it’s a response to a request of mine).
Yvan KOENIG (VALLAURIS, France) dimanche 4 juillet 2010 15:55:24