Page 1 of 1

Creating a List of all Capitalsied words

Posted: 2021-04-25 06:56:33
by GKS
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

Re: Creating a List of all Capitalsied words

Posted: 2021-04-26 09:02:49
by martin
Here's a macro that should do what you like:

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'
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.

Re: Creating a List of all Capitalsied words

Posted: 2021-04-26 10:12:31
by phspaelti
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.

Re: Creating a List of all Capitalsied words

Posted: 2021-04-26 10:15:11
by phspaelti
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. :(

Re: Creating a List of all Capitalsied words

Posted: 2021-04-26 11:38:19
by martin
phspaelti wrote: 2021-04-26 10:15:11 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. :(
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.