How to display Character Count without multiple clicks
How to display Character Count without multiple clicks
Hi everyone,
I'm looking for a way to display the character count in a file (or selected table) in a simpler way than by opening Tools, clicking on the Pencil, and viewing the Stats. Basically I would like to use a Menu Key or even a Keyboard Maestro macro to save time using this repetitive action that I perform on a regular basis.
Can anyone help?
Japan Rich
I'm looking for a way to display the character count in a file (or selected table) in a simpler way than by opening Tools, clicking on the Pencil, and viewing the Stats. Basically I would like to use a Menu Key or even a Keyboard Maestro macro to save time using this repetitive action that I perform on a regular basis.
Can anyone help?
Japan Rich
- martin
- Official Nisus Person
- Posts: 5228
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: How to display Character Count without multiple clicks
Here a couple of ways to get at the character count quicker:
1. Use the menu Window > Palettes > Statistics to show the stats palette as a floating palette, without the tool drawer showing. If you like this arrangement, you can keep it floating all the time and it will update to give information about the frontmost document.
2. Run the attached macro.
Naturally you could assign either of these a custom keyboard shortcut using our Menu Key preferences, for even easier access. I hope that helps!
One final note: these two methods may show different character counts. The stats palette does not count some ancillary text areas like table cells and footnotes, while the macro does.
1. Use the menu Window > Palettes > Statistics to show the stats palette as a floating palette, without the tool drawer showing. If you like this arrangement, you can keep it floating all the time and it will update to give information about the frontmost document.
2. Run the attached macro.
Naturally you could assign either of these a custom keyboard shortcut using our Menu Key preferences, for even easier access. I hope that helps!
One final note: these two methods may show different character counts. The stats palette does not count some ancillary text areas like table cells and footnotes, while the macro does.
- Attachments
-
- Character Counts.nwm
- (3.96 KiB) Downloaded 476 times
Re: How to display Character Count without multiple clicks
Martin,
Thank you so much for the "Character Counts" macro! It is great that the macro also counts within tables.
That's just what I needed, and I assigned a shortcut to it and now I'm set.
Would it be too much to ask for a similar macro for "Word Count"?
Japan Rich
Thank you so much for the "Character Counts" macro! It is great that the macro also counts within tables.
That's just what I needed, and I assigned a shortcut to it and now I'm set.
Would it be too much to ask for a similar macro for "Word Count"?
Japan Rich
Re: How to display Character Count without multiple clicks
Here's a macro that will give all the stats (character count, word count, paragraph count) in one window:JapanRich wrote:Would it be too much to ask for a similar macro for "Word Count"?
[Removed: see below]
Last edited by phspaelti on 2015-12-05 08:43:39, edited 1 time in total.
philip
Re: How to display Character Count without multiple clicks
Many, many thanks for this macro that includes word count and character count in the Statistics!
I've already set Menu Keys for the Palette and this Macro.
Much appreciated!
Japan Rich
I've already set Menu Keys for the Palette and this Macro.
Much appreciated!
Japan Rich
Re: How to display Character Count without multiple clicks
A request for modification of the Document Statistics macro.
I selected text across cells in a table, and the macro didn't work, citing:
'There was an error on line 22 in the macro "Document Statistics".
Expected a TextSelection object, not a Selection object.'
This is line 22 in the macro:
$doc.setSelection $docSelection
---
Is it possible for the macro to accommodate both? Or are separate macros needed depending on whether the selection is from a table or not?
Thanks for your attention to this matter! I'm really impressed.
Japan Rich
I selected text across cells in a table, and the macro didn't work, citing:
'There was an error on line 22 in the macro "Document Statistics".
Expected a TextSelection object, not a Selection object.'
This is line 22 in the macro:
$doc.setSelection $docSelection
---
Is it possible for the macro to accommodate both? Or are separate macros needed depending on whether the selection is from a table or not?
Thanks for your attention to this matter! I'm really impressed.
Japan Rich
Re: How to display Character Count without multiple clicks
Hello Rich,
I must say that I didn't spend much time testing the macro before posting it here. Sorry!
That said I can (a) confirm that it does fail as you say, and (b) admit that I am completely baffled by this error. The point that is baffling is that the instruction that fails is executed twice before "Line 22" and succeeds without complaint. I fail to understand what the problem is the third time around. The error message too is no help, since the ".setSelection" command should, and usually does, allow for a "Selection object".
I'll have to see what can be done about this.
[One simple temporary fix is to quote out lines 22, 23 and 32. This eliminates the reporting of the number of paragraphs in the selection, but otherwise works.]
I must say that I didn't spend much time testing the macro before posting it here. Sorry!
That said I can (a) confirm that it does fail as you say, and (b) admit that I am completely baffled by this error. The point that is baffling is that the instruction that fails is executed twice before "Line 22" and succeeds without complaint. I fail to understand what the problem is the third time around. The error message too is no help, since the ".setSelection" command should, and usually does, allow for a "Selection object".
I'll have to see what can be done about this.
[One simple temporary fix is to quote out lines 22, 23 and 32. This eliminates the reporting of the number of paragraphs in the selection, but otherwise works.]
philip
Re: How to display Character Count without multiple clicks
Philip,
I never need to know the number of paragraphs in a selection, only the character or word count, so if you are able to modify the macro to "quote out lines 22, 23 and 32", that would certainly suit my purposes!
Japan Rich
I never need to know the number of paragraphs in a selection, only the character or word count, so if you are able to modify the macro to "quote out lines 22, 23 and 32", that would certainly suit my purposes!
Japan Rich
Re: How to display Character Count without multiple clicks
Here is:
[removed: see below]
[removed: see below]
Last edited by phspaelti on 2015-12-05 08:44:22, edited 1 time in total.
philip
Re: How to display Character Count without multiple clicks
The revised Document Statistics macro displays the count in BOTH selection and document at the same time!
Excellent, thank you so much! I wonder how many Nisus users could use this macro!
Japan Rich
Excellent, thank you so much! I wonder how many Nisus users could use this macro!
Japan Rich
Re: How to display Character Count without multiple clicks
Okay, I figured out how to fix the problem.
philip
Re: How to display Character Count without multiple clicks
Hello Philip et al.,
There are scenarios where I need to see how much text the first, let's say, 6500 words of a document amounts to (the word number may differ), and how many pages it will require. If I do this manually, I have to select the text several times, until I finally find the exact number.
How can I select the first 6500 words of a document with a macro?
I tried the following crude macro, but it takes far too much time to complete. And why does the counter have to start with 21, if I want to find the first 6500 words, and with 5 if I want to find the first 1500?
Þorvarður
There are scenarios where I need to see how much text the first, let's say, 6500 words of a document amounts to (the word number may differ), and how many pages it will require. If I do this manually, I have to select the text several times, until I finally find the exact number.
How can I select the first 6500 words of a document with a macro?
I tried the following crude macro, but it takes far too much time to complete. And why does the counter have to start with 21, if I want to find the first 6500 words, and with 5 if I want to find the first 1500?
Code: Select all
Select All
Select Start
$counter = 21
While $counter <6500
Find @Text<(?:\b\w+\b)>, 'E'
Format:Text Color:Red
$counter = $counter + 1
End
Re: How to display Character Count without multiple clicks
Þorvarður wrote:How can I select the first 6500 words of a document with a macro
Code: Select all
$doc = Document.active
$words = $doc.text.findAll @Text<(?:\b\w+\b)>, 'E'
if $words.count > 6500
$sel = TextSelection.new $doc.text, Range.new (0, $words[6500].bound)
$doc.setSelection $sel
else
Prompt 'This document has only ' & $words.count & ' words'
end
Actually the real problem with your approach is that you are doing all that applying of red to the words one at a time, and doing it using regular "Find" in a loop.
philip
Re: How to display Character Count without multiple clicks
Grüezi Philip,
As always, thank you very much for your help. This is what I was looking for.
There seems to be a slight aberration though, because the macro selects 6,525 words instead of 6,500. If I want just 2 words selected and change the macro accordingly, I get 3 words selected instead of 2. This may increase proportionally, depending on which number I choose, but I have not looked closely into this yet to find a pattern.
As always, thank you very much for your help. This is what I was looking for.
There seems to be a slight aberration though, because the macro selects 6,525 words instead of 6,500. If I want just 2 words selected and change the macro accordingly, I get 3 words selected instead of 2. This may increase proportionally, depending on which number I choose, but I have not looked closely into this yet to find a pattern.
Re: How to display Character Count without multiple clicks
Actually what you will find is that the deviation is not proportional. The deviation where the macro selects 3 words instead of 2 is actually a "bug". Note that my original macro says $word[6500]. Since arrays are indexed from 0 this actually means that the macro should select 6501 words, not 6500. So as written the macro will always select one "word" extra. But any other deviations that you will find have to do with issues of the definition of "word", but also other technical differences which I am not even entirely sure about.
Consider the following example: The above file has 30 completely regular paragraphs with 5 * 100 word sentences of the form "Text text … text." for a word count total of 15,000. If you use the built-in document statistics you might find a word count of 14,910! If you try the "Select 6500 first words" macro then you should see that it selects 13 full paragraphs plus the first word of the 14th. The built-in stats report "6,462 words and 13 paragraphs", while my "Document Statistics" macro reports "6,501 words and 14 paragraphs".
Finally as another test, let's try the Nisus Macro Language Reference.
The "Select 6500 first words" macro will select all the way up to:
The built-in stats will report "5,675 words 533 paragraphs", the "Document Statistics" macro "6,430 words 647 paragraphs". Obviously the built-in stats live in a different universe, but why the disagreement with the "Document Statistics" macro? Who knows? The file we're checking contains many tables, and other types of 'broken-up' text as well as many 'strange' words. If you want to know exactly what's going on you can try the following modified version of the "Select 6500 first words" macro:
This macro will select the "words" individually, and you see that the built-in stats now comes much closer. (For me it shows 6,499 words). One thing that I find baffling is that it selects some of the content of the table in the section "Indexing" which is beyond the main body text that has been selected. Don't understand this.
At this point I have to say that this is beyond the point that I care about.
Consider the following example: The above file has 30 completely regular paragraphs with 5 * 100 word sentences of the form "Text text … text." for a word count total of 15,000. If you use the built-in document statistics you might find a word count of 14,910! If you try the "Select 6500 first words" macro then you should see that it selects 13 full paragraphs plus the first word of the 14th. The built-in stats report "6,462 words and 13 paragraphs", while my "Document Statistics" macro reports "6,501 words and 14 paragraphs".
Finally as another test, let's try the Nisus Macro Language Reference.
The "Select 6500 first words" macro will select all the way up to:
in the section "Commands > Formatting Text".Set Fixed Line Height points v2.0.7
Changes the paragraph’s line height to
The built-in stats will report "5,675 words 533 paragraphs", the "Document Statistics" macro "6,430 words 647 paragraphs". Obviously the built-in stats live in a different universe, but why the disagreement with the "Document Statistics" macro? Who knows? The file we're checking contains many tables, and other types of 'broken-up' text as well as many 'strange' words. If you want to know exactly what's going on you can try the following modified version of the "Select 6500 first words" macro:
Code: Select all
$doc = Document.active
$words = $doc.text.findAll @Text<\w+>, 'E'
if $words.count > 6500
$words6500 = $words.subarrayInRange Range.new(0,6500)
$doc.setSelection $words6500
else
Prompt 'This document has only ' & $words.count & ' words'
end
At this point I have to say that this is beyond the point that I care about.
philip