/****************************** * @title RemoveExcessSpacing * @author Luke Raymond * @info http://www.dispersiondesign.com * @version 1.0.0 *******************************/ try { RemoveExcessSpacing(); } catch(err) { var msg = "Please select a text frame containing"; msg += " the story you wish to format"; alert(msg); } function RemoveExcessSpacing() { var story; // Get the current selection var doc = app.activeDocument; var sel = doc.selection; var frame = sel[0]; if (frame && frame.constructor.name === "TextFrame") { story = frame.parentStory; } else { throw "No text frame selected"; } // Reset the Find/Change options app.findGrepPreferences = NothingEnum.nothing; app.changeGrepPreferences = NothingEnum.nothing; // Remove all multiple spaces app.findGrepPreferences.findWhat = " +"; app.changeGrepPreferences.changeTo = " "; story.changeGrep(); // Remove empty paragraphs and excess space at the end of paragraphs app.findGrepPreferences.findWhat = " *\\r[ \\r]*"; app.changeGrepPreferences.changeTo = "\\r"; story.changeGrep(); }