• 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: An arbitrary if.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: An arbitrary if.


  • Subject: Re: An arbitrary if.
  • From: Christopher Stone <email@hidden>
  • Date: Mon, 12 Sep 2011 16:07:25 -0500

On Sep 12, 2011, at 14:51, Alex Zavatone wrote:
I'm looking to see if I can set up a list of items I'd like to have anded in a logic statement and test for true or false.
______________________________________________________________________

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.

--
Best Regards,
Chris

----------------------------------------------------------------------------
# Using a combination of the Satimage.osax and the List & Record Tools.osax
# http://www.latenightsw.com/freeware/RecordTools/index.html
# http://tinyurl.com/dc3soh
----------------------------------------------------------------------------
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

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: An arbitrary if.
      • From: Christopher Stone <email@hidden>
References: 
 >An arbitrary if. (From: Alex Zavatone <email@hidden>)

  • Prev by Date: Re: An arbitrary if.
  • Next by Date: Get currencies conversion rate
  • Previous by thread: Re: An arbitrary if.
  • Next by thread: Re: An arbitrary if.
  • Index(es):
    • Date
    • Thread