Sure.
# Macro Make Word Lists from Index Topics
# v.1.0 2015/11/5
#
$doc = Document.active
# Prepare a hash for all the indexes
$indexes = Hash.new
# Check all the index styles
$indexNames = Text Index Names
foreach $indexName in $indexNames
# Prepare a hash for all the topic for a given index
$indexTopics = Hash.new
# Go through all the texts of the document and look for indexed items
foreach $text in $doc.allTexts
$loc = 0
while $loc < $text.length
$range = $text.rangeOfAttributesAtIndex $loc
$topics = $text.attributesAtIndex($loc).textIndexTopicsForStyleName($indexName)
# when we find an indexed item
if $topics
# save the selection of the indexed topic in the hash
foreach $topic in $topics
$sel = TextSelection.new($text,$range)
if $indexTopics.definesKey($topic)
if $indexTopics{$topic}.lastValue.bound == $sel.location
$prev = $indexTopics{$topic}.pop
$sel = $prev.unionKissingSelection $sel
end
$indexTopics{$topic}.push $sel
else
$indexTopics{$topic} = Array.new $sel
end
end
end
$loc = $range.bound
end
end
# save the selection hash for the given index
$indexes{$indexName} = $indexTopics
end
# generate output word list tables
# one for each index
foreach $indexName in $indexNames
$list = Array.new
foreach $topic in $indexes{$indexName}.keys
foreach $sel in $indexes{$indexName}{$topic}
if $topic.count
$indexAs = Cast to String $topic
$indexAs.replaceAll '", "', ':'
$indexAs.replaceAll '^\("', '', 'E'
$indexAs.replaceAll '"\)$', '', 'E'
else
$indexAs = '—'
# $indexAs = $sel.substring
end
$list.push $sel.substring & "\t" & $indexAs
end
end
$list.sort
$listDoc = Document.newWithText $list.join("\n") & "\n"
$listDoc.text.replaceAll '^(.+\n)\1+', '\1', 'E'
Select All
Convert to Table
end