Choke my throat and call me a smurf. I tested the script, and I am so positive it worked yesterday! But something goes wrong right at the very start — I stated that 'it should create the style automatically if it doesn't exist yet', and, for sure, that's the part where it fails!
Here is a new, improved version. Better, stronger, faster … well, it works. (I double-checked this time
)
If you have a dedicated “Underline” character style as well, it makes removing this a bit easier. Just delete the style “NoUnderline” and replace with “Underline”. Then re-run the script, and it will re-create the style. (Honestly.)
//DESCRIPTION: Begone, Ugly End Of Line Underlining!
// (c) Jongware 16-Dec-2009
var blankStyle = app.activeDocument.characterStyles.item(“NoUnderline”);
try { blankStyle.index; } catch(_)
{
blankStyle = undefined;
}
if (blankStyle == undefined)
{
blankStyle = app.activeDocument.characterStyles.add();
blankStyle.name = “NoUnderline”;
blankStyle.underline = false;
}
for (a=0; a<app.selection[0].lines.length; a++)
{
if (app.selection[0].lines[a].characters.item(-1).contents == ” “)
app.selection[0].lines[a].characters.item(-1).appliedCharacterStyle = blankStyle;
}