Hi John, Use the below script
// Collect broken words and place them (sorted, duplicates removed, exception list filtered out) in a new document
#target indesign;
if (app.documents.length > 0)
{
try {collect_broken_words ()}
catch (e) {alert (e.message + "\r(line " + e.line + ")")};
}
function collect_broken_words ()
{
var broken_words = find_broken_words (app.documents[0]);
broken_words = check_exceptions (broken_words);
var output = flow (broken_words.join ("\r"), 2);
}
function check_exceptions (word_list)
{
var pos;
var word_list = del_duplicates (word_list);
var lg = find_language ();
lg = app.findKeyStrings (lg)[0].replace ("$ID/", "");
var exceptions = app.userDictionaries.item (lg).addedWords;
// create array (dashless) of words in the exception list with all swung dashes removed
var dashless = exceptions.join ("£").replace (/~/g, "").split ("£");
for (var i = word_list.length-1; i > -1; i--)
{
pos = binsearch (word_list.replace ("~", "").toLowerCase(), dashless);
if (pos > 0)
word_list.splice (i, 1);
}
return word_list;
function del_duplicates (array)
{
var str = array.sort (nocase).join ("\r") +"\r";
str = str.replace (/([^\r]+\r)(\1)+/g, "$1");
return str.replace (/\r$/,"").split ("\r");
}
function nocase (a, b)
{
return a.toLowerCase () > b.toLowerCase ()
}
}
function find_broken_words (doc)
{
var broken = [];
var fnotes, j;
var stories = app.documents[0].stories.everyItem ().getElements ();
for (var i = 0; i < stories.length; i++)
{
if (stories.lines.length > 1)
{
broken = find_broken (stories, broken);
fnotes = stories.footnotes.everyItem().getElements();
for (j = 0; j < fnotes.length; j++)
if (fnotes .lines.length > 1)
broken = find_broken (fnotes , broken);
}
}
return broken
}
function find_broken (obj, array)
{
var part_1, part_2, w;
var lines_ = obj.lines.everyItem().contents;
var stop = lines_.length-1;
var re1 = /^.+[\s\u002F\u2013\u2014]/;
var re2 = /[\s\u002F\u2013\u2014].+$/;
var re_del = /[.,;:«»†‡®©‹›\[\]\{\}!?()0-9\u2018\u2019\u201C\u201D\/\r\n]/g;
for (var i = 0; i < stop; i++)
{
if (broken_line (lines_))
{
part_1 = lines_.replace (re1, "");
part_2 = lines_[i+1].replace (re2, "");
w = part_1+"~"+part_2;
w = w.replace (re_del, "");
array.push (w)
}
}
return array
}
function broken_line (s)
{
return "- \u2013\u2014\u00AD\r/".search (s.slice (-1)) < 0;
}
// Write array in a new document (after sorting and deleting duplicates)
function flow (s, col)
{
var doc = app.documents.add();
doc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
var marg = doc.pages[0].marginPreferences;
var gb = [marg.top, marg.left,
app.documentPreferences.pageHeight - marg.bottom,
app.documentPreferences.pageWidth - marg.right];
doc.textFrames.add ({geometricBounds: gb, contents: s, textFramePreferences: {textColumnCount: col}});
while (doc.pages[-1].textFrames[0].overflows)
{
doc.pages.add().textFrames.add ({geometricBounds: gb, textFramePreferences: {textColumnCount: col}});
doc.pages[-1].textFrames[0].previousTextFrame = doc.pages[-2].textFrames[0];
}
return doc;
}
function binsearch (srch, array)
{
return binsearch_sub (srch, array, 0, array.length-1)
}
function binsearch_sub (srch, array, first, last)
{
var temp, middle;
middle = Math.round ((first + last) / 2);
if (first > last)
temp = -1;
else
if (array[middle] == srch)
temp = middle;
else
if (array[middle] > srch)
temp = binsearch_sub (srch, array, first, middle-1);
else
temp = binsearch_sub (srch, array, middle+1, last);
return temp
}
// Find the applied language: if there's a selection, return the language of the applied paragraph style; otherwise if there's a document,
// return the language of the default paragraph style; if that doesn't work, return the language of the application's default paragraph style.
function find_language ()
{
try {var lg = app.selection[0].appliedParagraphStyle.appliedLanguage.name}
catch (_)
{
try {var lg = app.selection[0].parentStory.appliedLanguage.name}
catch (_)
{
try {var lg = app.documents[0].textDefaults.appliedParagraphStyle.appliedLanguage.name}
catch (_) {var lg = app.textDefaults.appliedParagraphStyle.appliedLanguage.name}
}
}
return lg
}
function get_time () {return new Date().getTime()}
function time_diff (start) {return (new Date() - start) / 1000}
... View more