• 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: Am I missing something here? I thought there was an elegant way to do this.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Am I missing something here? I thought there was an elegant way to do this.


  • Subject: Re: Am I missing something here? I thought there was an elegant way to do this.
  • From: Christopher Stone <email@hidden>
  • Date: Thu, 26 Apr 2012 22:52:27 -0500

On Apr 26, 2012, at 09:49, Alex Zavatone wrote:
set myRecord to every item of myList whose ( text contains "Safari")
______________________________________________________________________

Hey Alex,

You've already got most of the skinny on this from Axel and Shane, but...

The neatest if perhaps most abstruse method is Shane's ASObjC Runner (the caveat being that the predicate syntax has a little learning curve).

Then there's the old text-parsing method.

Egrep is pretty straightforward.

The Perl handler is more versatile but also a bit more syntactically complicated.

Then there's the venerable Satimage.osax.

I wish sed was more up-to-date; the version shipped with Lion is an old BSD variant.  GNU sed on the other hand has a case-insensitive switch that makes it easier to use.

--
Best Regards,
Chris

------------------------------------------------------------------------------------------------
# Case-Insensitive, Extended Regex
on filterListEgrep(srcList, regexStr)
set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, linefeed}
set cmd to "egrep -i '" & regexStr & "' <<< " & quoted form of (srcList as text)
set foundItems to paragraphs of (do shell script cmd)
set AppleScript's text item delimiters to oldTIDS
return foundItems
end filterListEgrep
------------------------------------------------------------------------------------------------
on filterListPerl(srcList, regexStr)
set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, linefeed}
set cmd to "perl -wlne 'if (m/" & regexStr & "/) {print \"$&\"}' <<< " & quoted form of (srcList as text)
set foundItems to paragraphs of (do shell script cmd)
set AppleScript's text item delimiters to oldTIDS
return foundItems
end filterListPerl
------------------------------------------------------------------------------------------------
on filterListSatimageOsax(findStr, srcList, caseSensitive)
try
set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, linefeed}
set srcList to srcList as text
set AppleScript's text item delimiters to oldTIDS
set findResult to find text findStr in srcList ¬
case sensitive caseSensitive ¬
all occurrences true ¬
string result true ¬
with regexp
return findResult
on error
return false
end try
end filterListSatimageOsax
------------------------------------------------------------------------------------------------
on filterListSed(srcList, regexStr)
set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, linefeed}
set cmd to "sed -nE '/" & regexStr & "/p' <<< " & quoted form of (srcList as text)
set foundItems to paragraphs of (do shell script cmd)
set AppleScript's text item delimiters to oldTIDS
return foundItems
end filterListSed
------------------------------------------------------------------------------------------------

set _list to {"Safari-01", "two", "three", "four", "five", "six", "Safari-7", "Safari", "Safari_5.1.5"}

filterListEgrep(_list, "saf")
filterListEgrep(_list, "\\bsafari\\b")
filterListEgrep(_list, "^f")

filterListPerl(_list, "(?i).*safari.*")
filterListPerl(_list, ".*Safari$")
filterListPerl(_list, "^f.+")

filterListSatimageOsax(".*Safari.*", _list, false)
filterListSatimageOsax(".*saf.*", _list, false)
filterListSatimageOsax(".*\\d+.*", _list, false)
filterListSatimageOsax("^f.+", _list, false)

filterListSed(_list, "Safari")
filterListSed(_list, "Safari[^0-9]*[0-9]$")
filterListSed(_list, "^f")

------------------------------------------------------------------------------------------------

 _______________________________________________
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: Am I missing something here? I thought there was an elegant way to do this.
      • From: Shane Stanley <email@hidden>
    • Re: Am I missing something here? I thought there was an elegant way to do this.
      • From: Alex Zavatone <email@hidden>
References: 
 >Safari Tab Pick-List (From: Christopher Stone <email@hidden>)
 >Re: Safari Tab Pick-List (From: Alex Zavatone <email@hidden>)
 >Re: Safari Tab Pick-List (From: Christopher Stone <email@hidden>)
 >Re: Safari Tab Pick-List (From: Alex Zavatone <email@hidden>)
 >Re: Safari Tab Pick-List (From: Christopher Stone <email@hidden>)
 >Am I missing something here? I thought there was an elegant way to do this. (From: Alex Zavatone <email@hidden>)

  • Prev by Date: Re: Am I missing something here? I thought there was an elegant way to do this.
  • Next by Date: Re: Am I missing something here? I thought there was an elegant way to do this.
  • Previous by thread: Re: Am I missing something here? I thought there was an elegant way to do this.
  • Next by thread: Re: Am I missing something here? I thought there was an elegant way to do this.
  • Index(es):
    • Date
    • Thread