Count multiple text boxes in Quarkxpress

Hello,
have a problem to count all text from a selection of 2 o more Quarkxpress text boxes not linked (characters and words)

Count all text from a selected text box is easy.
Count all from text selection is easy too, but count text of multiple selection…mmm???

Have this scripts working, one counts all text from one text box selection, the other counts all text from selection.
How to count all text from multiple text box selection?

For the selected box:

tell application “QuarkXPress Passport”

display dialog (("Hay " & (count of every character of current box of current page of document 1) as string) & " caracteres" & " y " & (count of every word of current box of current page of document 1) as string) & " palabras" buttons {"OK"} default button 1

end tell

For all text selection:

tell application “QuarkXPress Passport”

display dialog ("Hay " & (count of every character in the contents of selection) as string) & (" y " & (count of every word in the contents of selection) as string) & " palabras" buttons {"OK"} default button 1

end tell

Any help please?
Thank’s
Xavier Dalfo

Well, I post the same question on Quarks Forums and somebody answer this:

you need to get the script to count each box individually and then add up the totals. The script below does this.

It first looks to see which and how many boxes are selected. Then, using this information in a REPEAT statement, it counts the words and characters in the first box, adds it to a Total and then goes on to the next box.

At the end it displays the dialog as you had it. This should work across multiple pages etc, just MAKE SURE TO HAVE THE BOXES SELECTED.

Code:


set thetotalwords to 0 
set thetotalcharacters to 0 

tell application "QuarkXPress Passport" 
   tell document 1 
      set theselected to every text box whose selected is true 
      set numberofboxes to count of theselected 
       
      repeat with x from 1 to numberofboxes 
         set thebox to item x of theselected 
          
         set thecharacters to count every character of thebox 
         set thetotalcharacters to thetotalcharacters + thecharacters 
          
         set thewords to count of every word of thebox 
         set thetotalwords to thetotalwords + thewords 
          
      end repeat 
       
      display dialog ("Hay  " & thetotalcharacters & " caracteres.  " & thetotalwords & " palabras.") buttons {"Ok"} default button 1 
       
   end tell 
end tell