• 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: Count word's occurences
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Count word's occurences


  • Subject: Re: Count word's occurences
  • From: Shane Stanley <email@hidden>
  • Date: Mon, 08 Sep 2014 19:36:35 +1000

On 8 Sep 2014, at 5:53 pm, Guido Tangorra <email@hidden> wrote:

This is working fine, but I'm wondering if there's a better or a more efficient way to do the same. Maybe with grep or ASObjC Runner or with a built-in command in TextWrangler.

It's pretty easy to do with an ASObjC-based library in Mavericks or later -- there's a class just for the job:

use framework "Foundation"

on indexList:theList
set theCountedSet to current application's NSCountedSet's alloc()'s initWithArray:theList
set theEnumerator to theCountedSet's objectEnumerator()
set newList to {}
repeat
set anObject to theEnumerator's nextObject()
if anObject is missing value then exit repeat
set theCount to theCountedSet's countForObject:anObject
set end of newList to {anObject as text, theCount}
end repeat
return newList
end indexList:

-- 
Shane Stanley <email@hidden>
<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

  • Follow-Ups:
    • Re: Count word's occurences
      • From: Shane Stanley <email@hidden>
References: 
 >Count word's occurences (From: Guido Tangorra <email@hidden>)

  • Prev by Date: Count word's occurences
  • Next by Date: Re: Count word's occurences
  • Previous by thread: Count word's occurences
  • Next by thread: Re: Count word's occurences
  • Index(es):
    • Date
    • Thread