• 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: Guido Tangorra <email@hidden>
  • Date: Mon, 15 Sep 2014 11:06:21 +0200

Hi Deivy,
I tried your solution and it work. It's also very fast.
But after a while it give this error:
expected "," or "}" but found unknow token

Guido.


2014-09-13 21:41 GMT+02:00 Deivy Petrescu <email@hidden>:
Guido,
I was intrigued by your question and was disappointed that there was no way to get the word count of a text being created on the fly.
So I set up to try to find a way.
I know you have something already working, I don’t have JSON helper and, so far, no use for it.
Also, no TextWrangler (BBEdit).
However, I think I came up with a way to write the new line and the numbers of times it shows up before on the fly.
I can not comment on speed but I assume it would be much faster than the one you have since I don’t really have to count the number of occurrences of a word, however, I can not test, just speculate.

I’ve used parts of Nigel’s version, I’d appreciate if you let me know it works for you.
Thanks.
Here is the script


<script>
set theDocName to "theDocName"
set lista to {}
set wordcount to {}
tell application "TextWrangler"
        activate
        set myDocument to make new text document with properties {name:theDocName}
        set show line numbers of myDocument to false
end tell

on idle
        global lista
        global wordcount
        tell application "JSON Helper" to set myFruit to fetch JSON from mySource
        if myFruit is in lista then
                try
                        set wc to wordcount as string
                on error e
                        set e to text (get offset of "{" in e) thru (get offset of "}" in e) of e
                end try
                set {wordcount, kount} to run script "set  nue  to " & e & "\n\t\tset  nue's " & myFruit & " to  nue's " & myFruit & " + 1\n\t\treturn {nue,nue's " & myFruit & " }"
        else
                set end of lista to myFruit
                set {wordcount, kount} to {wordcount & (run script "{" & myFruit & ":1}"), 1}
        end if
        tell application "TextWrangler"
                tell text of front text window
                        make new line at end with data (myFruit & space & kount)
                        select insertion point -1
                end tell
        end tell

        return 0.5
end idle

</script>

Deivy Petrescu
email@hidden






--
Saluti,
Guido Tangorra
 _______________________________________________
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: Deivy Marck Petrescu <email@hidden>
    • Re: Count word's occurences
      • From: Thomas Fischer <email@hidden>
References: 
 >Re: Count word's occurences (From: Nigel Garvey <email@hidden>)
 >Re: Count word's occurences (From: Guido Tangorra <email@hidden>)
 >Re: Count word's occurences (From: Nigel Garvey <email@hidden>)
 >Re: Count word's occurences (From: Nigel Garvey <email@hidden>)
 >Re: Count word's occurences (From: Guido Tangorra <email@hidden>)
 >Re: Count word's occurences (From: Deivy Petrescu <email@hidden>)

  • Prev by Date: Controlling Thunderbird using System Events
  • Next by Date: Re: Count word's occurences
  • Previous by thread: Re: Count word's occurences
  • Next by thread: Re: Count word's occurences
  • Index(es):
    • Date
    • Thread