• 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
Dynamic Records?? (or other alternatives)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Dynamic Records?? (or other alternatives)


  • Subject: Dynamic Records?? (or other alternatives)
  • From: Greg Back <email@hidden>
  • Date: Tue, 27 Nov 2001 17:15:19 -0500

Hi all-
I have set out on my first really helpful applescript, not like the
pointless scripts i have been writing. Essentially, it will work on the text
on the clipboard and provide a word-count feature, counting the total number
of words and providing a separate count for each individual word (i.e. have
the output be "2 occurence(s) of 'Applescript', 1 occurence of 'Script'", or
the like). So far, I have the following script:

======================================================================

set theText to the clipboard
set finallist to {}
--store, set TIDS
set {oldtids, text item delimiters} to {text item delimiters, " "}
set wrdlist to the text items of theText
set wrdcount to count wrdlist
repeat with wrd in wrdlist
if wrd is not in finallist then
set end of finallist to wrd
else
--somehow signify that there are more than one of this word
end if
end repeat
set diffWrdCount to count finallist
--somehow set commonword to word with the highest count
--sort wrdlist according to which words have the highest occurences
set commonword to "the"
display dialog "There are " & diffWrdCount & " different words out of
[NO-BREAK]" & wrdcount & " words on the clipboard. The most common
[NO-BREAK]word is \"" & commonword & "\"."
--restore TIDS
set text item delimiters to oldtids

======================================================================
[formatted using ScriptToEmail - gentle relief for mailing list pains]
[http://files.macscripter.net/ScriptBuilders/ScriptTools/ScriptToEmail.hqx]
======================================================================

My first general question is :

1) Is there already a utility out there that can do this? No use in
re-inventing the wheel. Even if there is, i still want to do this using
Applescript, if only for the exercise.

The main reason for my post is:

2) Can you create a record during the running of a script, such as

set wrdz to {"applescript":2 , "script":1}

adding a new entry for each new word the script encounters. Or are records
not the way to do this? Or do I need to go about the entire process a
different way. From what I can tell, you have to define everything in the
record before it is run. Am i wrong?

Other issues i have to deal with in writing this script:

3) A word at the end of a sentence, or right before a comma, will be treated
differently by the script. A possible workaround might be (in
pseudo-script):

set badchars to (every item of ".,!?()") as list --Others?
if any character of wrd is in badchars then
--somehow take it off

Is there any way to do this without stepping through each character using
TIDs?

4) I also need to figure out how to return the result to the user, but I
haven't decided how (new text file, on clipboard, series of dialogs, etc.).
This also depends on how the data is stored at the end of the script. I
figure i'll cross this bridge when i get to it, but i am bringing it up now.
Any suggestions?

Thanks for taking the time to read such a long post!!, and Thanks in Advance

Greg Back


  • Follow-Ups:
    • Re: Dynamic Records?? (or other alternatives)
      • From: email@hidden (Michael Sullivan)
  • Prev by Date: Applescript FAQ's (was: Re: Passing parameter to Unix commands and then executing)
  • Next by Date: Stone Create and AppleScript for Applications
  • Previous by thread: Applescript FAQ's (was: Re: Passing parameter to Unix commands and then executing)
  • Next by thread: Re: Dynamic Records?? (or other alternatives)
  • Index(es):
    • Date
    • Thread