I'm working through a document where I would like to find a way to extract and have in a new list all that document's words which are written in ALL CAPS. I would then use that list to prepare an annex of Acronyms used in this document.
Is there a macro that could help reduce the tedious chore of manually selecting and cutting/pasting each entry?
Glen
Creating a List of all Capitalsied words
- martin
- Official Nisus Person
- Posts: 5230
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: Creating a List of all Capitalsied words
Here's a macro that should do what you like:
The only thing you might want to adjust is the $minLength variable. It's a threshold that controls the minimum number of characters in a single word. Two is a good default so you can avoid matching words like "I", or "A" at the start of a sentence.
Code: Select all
# This macro finds all words that are in all caps in the frontmost document
$minLength = 2
If ! Find All @string<\p{Upper}{$minLength,}>, 'E-i'
Prompt "No matches found.", "Did not find any words in all caps with at least $minLength characters."
Exit
End
# gather list of matching words, de-duplicate them, and sort
$doc = Document.active
$wordList = Array.new
$wordMap = Hash.new
ForEach $selection in $doc.textSelections
$word = $selection.substring
If ! $wordMap{$word} # ensure unique
$wordMap{$word} = @true
$wordList.appendValue($word)
End
End
$wordList.sort
# open a new document showing all matches
$wordText = $wordList.join("\n")
Document.newWithText($wordText)
Menu 'View:Draft View'
Re: Creating a List of all Capitalsied words
While Martin' macro will work fine for this, one might mention that you don't really need a macro for this at all. Just create an appropriate Find expression, do "Find All" to get a non-contiguous selection and then you can copy them directly to the clipboard.
- Attachments
-
- Screen Shot 2021-04-27 at 3.11.44.png (112.77 KiB) Viewed 11771 times
philip
Re: Creating a List of all Capitalsied words
I would have used PowerFind for the screen-shot, but it seems that PowerFind won't let you insert a repeat bubble with (3 or more). It creates the bubble, but it just beeps and won't insert it in the Find dialog. 

philip
- martin
- Official Nisus Person
- Posts: 5230
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: Creating a List of all Capitalsied words
This looks like a bug, if you leave the upper bound blank. If you enter a real number (like 999) the repetition bubble inserts correctly.