Then, of course, I realised that I also needed to be able to count the words in one or more selected shapes (in addition to the count for the whole canvas).
so I needed version two, pasted below.
Code:
property pTitle : "Word Count for OmniGraffle"
property pVersion : ".002"
-- Ver 2 adds a postscript giving a separate total for words in those shapes which are currently selected.
set text item delimiters to space
tell application id "com.omnigroup.OmniGrafflePro"
set oWin to front window
tell canvas of oWin
set lngWords to count of words of ((text of solids) as text)
set {strCanvas, strDoc} to {name, name of oWin}
end tell
set lngSelnWords to 0
set lngSolids to 0
set lstSeln to selection of oWin
if length of lstSeln > 0 then
repeat with oGraphic in lstSeln
try
set lngSelnWords to lngSelnWords + (count of words of text of oGraphic)
set lngSolids to lngSolids + 1
end try
end repeat
end if
set strReport to (lngWords as string) & " words in" & return & return & strCanvas ¬
& " of " & return & return & strDoc
if lngSelnWords > 0 then
set strReport to ((strReport & return & return & "(Including " & lngSelnWords as string) & ¬
" words in " & lngSolids as string) & " selected " & my pl(lngSolids, "shape") & ")."
end if
display dialog strReport buttons {"OK"} with title pTitle & " Ver " & pVersion with icon 1
end tell
on pl(lngNum, strTerm)
lngNum
if absolute(lngNum) is not 1 then
strTerm & "s"
else
strTerm
end if
end pl
on absolute(num)
if num < 0 then
-num
else
num
end if
end absolute