You must be logged in to post Login

Search Forums:


 






Removing End of Line Underlines

UserPost

4:36 pm
December 16, 2009


emilydorr

Community Member

posts 5

Is there a way to remove the underlined space, that falls at the end of a line of text, that has underlines applied to multiple lines of text?

Emily Dorr Art Director, Jean Peterson Design

8:53 pm
December 16, 2009


Jongware

Member

posts 765

Yes, that's annoying. ID cannot find/change something based on soft line endings, so a Javascript would come in handy. (Audience: "Javascript?") Sure, no problem. Copy and paste the following one into a plain text editor (Notepad, TextEdit in plain text mode; best is Adobe's own ESTK editor that comes installed with InDesign) and save into your User Scripts folder as "NoUnderline.jsx". Select an appropriate amount of text, and run the script. It will add a character style to underlined spaces at the end of each line, and leave other end characters (such as soft hyphens) alone. If your text changes and you want the underlines back, do the following:

1. Edit the character style "NoUnderline"; set Underlining on.

2. Delete the character style; select "Preserve Formatting".

3. Run the script again on your selection of text.

Alternatively, select a run of text and remove the character style by replacing it with "[None]" and restore Underline in the Change Formatting box.

Here's the script:



//DESCRIPTION: Begone, Ugly End Of Line Underlining!

// (c) Jongware 16-Dec-2009



try {

 blankStyle = app.activeDocument.characterStyles.item("NoUnderline");

} catch (_)

{

 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;

}

3:40 pm
December 17, 2009


emilydorr

Community Member

posts 5

Thank you for helping me. I receive an error when I try to run the script.I am not very familiar with running scripts but have followed your directions to the "T" Again thanks for the help. Maybe I am doing something wrong?


Error Number 30477

Error String: Invalid value for set property

'appliedCharacterStyle.' Expected CharacterStyoe or

String, but received nothing.

Then it refers to where I have the script save followed by

Line:31

Source app.selection.[0].lines[a].character.items(-1).appliedC

haracterStyle = blankStyle;

Emily Dorr Art Director, Jean Peterson Design

8:36 pm
December 17, 2009


Jongware

Member

posts 765

That's odd. The script is written & tested for CS4, but it ought to work for CS3 as well. (You are not using an even older version, are you?)

Can you check if it actually creates a character style called "NoUnderline"? If there isn't one, it should make it automatically. (FYI, the variable 'blankStyle' should point to this character style, and should apply it in lline 31.)

It seems you didn't do anything wrong copying or running the script, as it would never have made it all the way to that line.

8:50 pm
December 17, 2009


emilydorr

Community Member

posts 5

I am in CS4. And it didn't make a "NoUnderline" character style.Hummm

The whole document is layed out with Character Styles because the person who typeset in Microsoft Word used all "Normal" text. Does that make since? But had about 7 different formattings applied throughout the whole document. Guess they don't know how to use styles in Word.

I imported the text into InDesign, then did a change font for the fonts I used in my Characters Styles. Then went in and did a "Find/Change" to apply my Character Styles to the whole document. Normally I would use Paragraph Styles and then apply individual Character Styles but because of the Word document formatting the only thing that worked was all Character Styles.

Sorry for the long explanation but I thought it might help troubleshoot the javascript issue.

Emily Dorr Art Director, Jean Peterson Design

9:17 pm
December 17, 2009


Jongware

Member

posts 765

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 Cool)

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;

}


6:02 pm
December 18, 2009


emilydorr

Community Member

posts 5

Still doesn't seem to work for me.


JavaScript Error!

Error Number: 8

Error String: Syntax Error

Then it names where it is save on my computer followed by

Line: 5
var blankStyle = app.activeDocument.characterStyles.item("NoUnderline")

Offending Text: "


As I am not a script user I don't know how to trouble shoot. I really appreciate all your efforts.

Emily Dorr Art Director, Jean Peterson Design

9:30 pm
December 18, 2009


Jongware

Member

posts 765

Ouch! Fortunately, you copied the error message exactly, so I can tell you right away what's wrong. (I hope.)

Since this forum is brand new, there isn't as yet an option to format code. I gave it a manual try in my first post, underhandedly editing the raw HTML for the message, so the script would show up as plain code. And one of the things that happen automatically is that double quotes do not get translated into the curly ones that show up in text! (Let me show. I type "Hey, Emily, cheer up! Almost there!" with straight quotes in the message editor. You'll see them as curly ones on your screen.)

As it was a sort of hacking David's otherwise very pretty new forum, and it also was a bit of trouble (and not really worth that either), I plainly copied the new script out of my editor into the message editor. And, well, there's when it went wrong. Both single quotes (which I didn't use) and double quotes in a script need to be of the straight up kind. If you use Adobe's own ESTK to edit the script, you'll see it recognizes the text strings and will change its colour when changed to the correct quotes.

Let's say I'm fairly confident it ought to work now.

6:47 pm
December 21, 2009


emilydorr

Community Member

posts 5

Oh my. This is like an early Christmas present! It worked. I don't know how to thank you enough. Hope it didn't take up too much of your time. I think I will tell my client they get to see the pesky underlines until the last proof and then I'll run the script on however many pages the book turns into, right now it is looking like she is writing a 800+ page book and she likes her underlines!


Thanks again.

Emily Dorr Art Director, Jean Peterson Design

6:55 pm
December 22, 2009


David Blatner

Admin

posts 830

That is awesome, Theun! I have posted the script here (with straight quotes), in case anyone else wants to grab it more easily.

http://www.indesignsecrets.com.....rlines.jsx

(right click on the link to download it to disk, and save it in your scripts folder, as mentioned here)

co-host, InDesignSecrets.com

12:47 pm
March 30, 2010


AnkeG

New Member

posts 1

Oh my, I have been searching for a solution for this for 2 hours and finally came to this post.

Thank you soooo much, the second script worked for me, OS 10.6.2, InDesign CS3 :-)