script for Apple Works 5

Here is the script. It works with scriptable text editor, but not with AppleWorks.

set mymessage to "The selection"
tell application "AppleWorks"
if front document exists then
  if length of selection > 0 then
    set word_count to number of words of selection
    set message to "The selection"
  else
    set Character_count to number of characters of front document
    set mymessage to """ & (name of front document) & """
  end if
  set myinches to Character_count / 245
  --set mymessage to mymessage & " contains " & Character_count & " words."
  set mymessage to mymessage & " contains " & myinches & " Inches."
  display dialog mymessage buttons {"OK"} --default button "OK" with icon note
else
  error "There is no open document."
end if
end tell

Are you sure this works in Script Editor? The dialog box displays the column inches only when the selection <= 0; that is when there is no selection. If there is a selection the variable character_count is never defined (and thus cannot be divided by 245). The variable word_count is set to a number of words, but not used. (I assume you posted only part of the script, and it is used elsewhere.) The word “error” cannot be used; it is reserved word(as “if” is) used in try…on error…end statements. There is a “set message to ‘the selection’” following the first “then”. Shouldn’t this be “set mymessage” and if it is, isn’t needed because you define mymessage prior to the tell block (but see below). Note that if the selection = “ote that i” from the first three words sentence, then Appleworks returns that 3 words are selected, although only parts of two are selected. That may not be what you want. This script may be closer to what you want:

tell application "AppleWorks"
if front document exists then
  if length of the selection > 0 then-- there is a selection
    set word_count to number of words of selection-- why not characters, as below?
    set my inches to word_count-- math for converting words to inches???
    set my message to "Selection from "" & (name of front document) & """ & " contains " & word_count & " words."
else-- there isn't a selection 
  set Character_count to number of characters of front document -- all characters in front doc
  set myinches to characters 1 thru 8 of ((Character_count / 245) as text) 
  -- change not required
  set mymessage to """ & (name of front document) & """ & " contains " & myinches & " Inches."
end if else
set mymessage to "There is no open document."
end if
-- show the result 
display dialog mymessage buttons {"OK"} --default button "OK" with icon note
end tell

BTW (and my experience is based on Appleworks 6):you might want to change number of characters of front documenttonumber of characters in text body of front document. Without the “text body”, the count will include items in headers and footers!

To MacGuy:
Using your script, I get the Execution Error message: That is not a property of the specified class.
It hangs on the 0 in greater than 0 statement.
I appreciate your help.
J.A.B.

So “length of the selection” does not work in AW5? I’m surprised, but I can test it only on AW6.
mg