• 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: Shane Stanley <email@hidden>
  • Date: Tue, 13 Sep 2011 11:00:17 +1000

Late as usual. Here's an AppleScriptObjC method that filters the list using containment as a test, and compares before and after.

set x to "this is a cat"
set myList to {"this", "cat"}
-- make test;%@ is replaced by value of x
set aPredicate to current application's NSPredicate's predicateWithFormat_("%@ contains[cd] SELF", x)
-- make array from list 
set myArray to current application's NSArray's arrayWithArray_(myList)
-- filter array  
set newList to myArray's filteredArrayUsingPredicate_(aPredicate)
-- compare before and after 
myList = newList as list

From the log:

00.0000 -- Start --
00.0011 set x to "this is a cat"
--> this is a cat
00.0005 set myList to {"this", "cat"}
--> {this, cat}
00.0004 set aPredicate to current application's NSPredicate's predicateWithFormat_("%@ contains[cd] SELF", x)
--> "this is a cat" CONTAINS[cd] SELF
00.0004 set myArray to current application's NSArray's arrayWithArray_(myList)
--> {this, cat}
00.0004 set newList to myArray's filteredArrayUsingPredicate_(aPredicate)
--> {this, cat}
00.0003 myList = newList as list
--> true
00.0001 -- End -- (~0.017s)

-- 
Shane Stanley <email@hidden>
'AppleScriptObjC Explored' <www.macosxautomation.com/applescript/apps/>

 _______________________________________________
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

References: 
 >An arbitrary if. (From: Alex Zavatone <email@hidden>)
 >Re: An arbitrary if. (From: Christopher Stone <email@hidden>)
 >Re: An arbitrary if. (From: Christopher Stone <email@hidden>)
 >Re: An arbitrary if. (From: "Mark J. Reed" <email@hidden>)
 >Re: An arbitrary if. (From: Alex Zavatone <email@hidden>)
 >Re: An arbitrary if. (From: "Mark J. Reed" <email@hidden>)
 >Re: An arbitrary if. (From: Alex Zavatone <email@hidden>)

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