Copy link to clipboard
Copied
Try this, "char" is a reserved word you can't use as variable name
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Revert underlining");
function main () {
var story = app.selection[0].parentStory;
var lines = story.lines.everyItem().getElements();
for (var i = 0; i < lines.length; i++) {
var c = lines[i].characters[-1];
if (c.underline && c.contents == " ") {
c.underline = false;
}
}
}
Also, I added a undo 🙂
Copy link to clipboard
Copied
You may not like this answer, but if you don't want the underline to carry over into the space when underline an entire paragraph, you need to remove the current underlining and then redo it individually for each line of the paragraph.
Wish I had better news for you,
Randy
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I frankly don't know.
But if you define the underline by a script, it's going to have to be pretty savvy to re-define the fix if there are any copyfit changes. At least if you do it by hand, it can be pretty easily fixed/changed by hand if it's needed.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Ow. My heart's with you, and my hand is instinctively cramping at the thought of it.
BrianP has provided a script below that'll hopefully work for you, but I'd wait to use it until the job is finally, entirely, set in stone.
Good luck,
Randy
Copy link to clipboard
Copied
With your text cursor selected into the text:
var story = app.selection[0].parentStory;
var lines = story.lines.everyItem().getElements();
var char;
for (var i = 0; i < lines.length; i++) {
char = lines[i].characters[-1];
if (char.underline && char.contents == " ") {
char.underline = false;
}
}
Of course, this is pretty risky if the text flow changes.
If there was no hyphenation or other cause to ensure the last character in a line was a space, you could just make it a one-liner:
app.selection[0].parentStory.lines.everyItem().characters.lastItem().underline = false;
Copy link to clipboard
Copied
Hi Brian! Thanks! I actually don't really know how the handle or use this script - as I am not really used to do so... Could you tell me where to put or copy-paste it? Thanks!
Copy link to clipboard
Copied
Click in your text with your text tool then run the script. It will work on all linked text frames for that story.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Sorry, I don't know what that error means. Ensure you saved the script as a plain text file with the .jsx extension, select inside a text frame with your cursor and try to execute the script. Was there other text besides that error line?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
If using Text Edit in Mac, make sure you select the Make Plain Text option.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Are you still getting the error "This file cannot be executed by any of the supported scripting languages”?
If so, there is an issue with how you are saving the script to your file. It should have a .jsx extension. Try uploading a screenshot of the file info for the script file.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Try this, "char" is a reserved word you can't use as variable name
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Revert underlining");
function main () {
var story = app.selection[0].parentStory;
var lines = story.lines.everyItem().getElements();
for (var i = 0; i < lines.length; i++) {
var c = lines[i].characters[-1];
if (c.underline && c.contents == " ") {
c.underline = false;
}
}
}
Also, I added a undo 🙂
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi there, I appreciate this post is over 2 years old but wondering if you can help here as the OP described exactly the same issue I'm having. The solution appears very elegant but my scripting knowledge is pretty minimal and when I try the above I am getting this error.
Any clues what I might be doing wrong?
Copy link to clipboard
Copied
Ignore previous post, I restarted Indesign and it works a peach - thank you so much for this script, it's amazing!
Copy link to clipboard
Copied
Not sure why you wanna use a script for that... a simple GREP within the paragraph style does it:
\s(?=\n|$)
Copy link to clipboard
Copied
Posted the wrong screenshot, here you actually see it working:
Copy link to clipboard
Copied
Copy link to clipboard
Copied
- The paragraph style has underline checked.
- The character style is set to not underline.
- Via GREP you apply the non-underline character style to every space at the end of the line.
But I just realized you have to set a manual line break in order for the GREP to work.
I don't know if there is a expression for automatic breaks...
Copy link to clipboard
Copied