Hey Alex,
You can't do that with vanilla Applescript, but I can think of a couple of ways using osaxen.
I use the fnd() handler all the time for testing true/false, but I have it set up to return a boolean only if something is not found. I think though that I'll go ahead and and findBool() to my handler set.
I see Luther has already posted the repeat version.
I use the regex method all the time for various tests, and it's very fast.
The first method might even be faster, but this is a small test sample.
To be fair the repeat method is really quite fast as well.
----------------------------------------------------------------------------
# Using a combination of the Satimage.osax and the List & Record Tools.osax
----------------------------------------------------------------------------
set x to "this is a cat"
set myList to {"this", "cat"}
set xList to words of x
(intersection of myList and xList) = (sortlist myList)
--> True
# intersection of --> List & Record Tools.osax
# sortlist --> Satimage.osax
----------------------------------------------------------------------------
# Using only the Satimage.osax
----------------------------------------------------------------------------
on fnd(findStr, srcData, caseSensitive, allOccurrences, stringResult)
try
set findResult to find text findStr in srcData ¬
case sensitive caseSensitive ¬
all occurrences allOccurrences ¬
string result stringResult ¬
with regexp
return findResult
on error
return false
end try
end fnd
----------------------------------------------------------------------------
set x to "this is a cat"
set myList to {"this", "cat"}
set myListSorted to join (sortlist myList) using ".*"
set xList to join (sortlist (words of x)) using " "
if fnd(myListSorted, xList, false, false, true) ≠ false then
set foundFlag to true
else
set foundFlag to false
end if
----------------------------------------------------------------------------
----------------------------------------------------------------------------
# Alternatively
----------------------------------------------------------------------------
on fndBool(findStr, srcData, caseSensitive, allOccurrences, stringResult)
try
set findResult to find text findStr in srcData ¬
case sensitive caseSensitive ¬
all occurrences allOccurrences ¬
string result stringResult ¬
with regexp
return true
on error
return false
end try
end fndBool
----------------------------------------------------------------------------
set x to "this is a cat"
set myList to {"this", "cat"}
set myListSorted to join (sortlist myList) using ".*"
set xList to join (sortlist (words of x)) using " "
fndBool(myListSorted, xList, false, false, true)
----------------------------------------------------------------------------
----------------------------------------------------------------------------
# Changing Luther's script just a bit to exit repeat on first NOT.
----------------------------------------------------------------------------
set x to "this is a cat"
set myList to {"this", "cat"}
set myResult to true
set xList to words of x
repeat with aword in myList
if not (xList contains aword) then
set myResult to false
exit repeat
end if
end repeat