Skip to main content
Participant
October 8, 2024
Answered

Using Script to Automate Insertion of Thin Space for Company Name in InDesign

  • October 8, 2024
  • 4 replies
  • 518 views

Hello everyone,

 

I'm reaching out to see if it's possible to create a script to automate a specific task. I work daily for a company whose name contains a thin space (for example: N (thin space) NAME = N NAME).

 

The issue is that I sometimes forget to add this space when formatting lengthy documents.

 

I’d like to know if it’s possible to create a script that automatically detects the company’s name (N NAME) and inserts the thin space between “N” and “NAME” whenever the name is written.

 

Thank you so much for your help, and have a great day!

 

 

<Title renamed by MOD>

This topic has been closed for replies.
Correct answer Willi Adelberger

Instead of inserting a space use a character style with expanded tracking for the space before.  This can be automatically applied via GREP style.

4 replies

Willi Adelberger
Community Expert
Willi AdelbergerCommunity ExpertCorrect answer
Community Expert
October 8, 2024

Instead of inserting a space use a character style with expanded tracking for the space before.  This can be automatically applied via GREP style.

m1b
Community Expert
Community Expert
October 8, 2024

Hi @Océane23259082birw, you could do this as a straight find grep, without a script:

If you need a script, this does pretty much the same thing—using find/change grep. It will target the selected text/textframe(s) or, if nothing selected, the whole document.

- Mark

 

 

function main() {

    var doc = app.activeDocument,
        targets = doc.selection;

    app.findGrepPreferences = NothingEnum.NOTHING;
    app.changeGrepPreferences = NothingEnum.NOTHING;

    app.findGrepPreferences.properties = {
        findWhat: '(?<=\\bN)\\s(?=Name\\b)',
    };

    app.changeGrepPreferences.properties = {
        changeTo: '~%',
        noBreak: true,
    };

    if (0 === targets.length)
        targets = [doc];

    for (var i = targets.length - 1; i >= 0; i--)
        if (undefined != targets[i].changeGrep)
            targets[i].changeGrep();

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Apply N Name Spacing');

Edit 2024-10-08: added check to see if selected item was greppable.

 

JR Boulay
Community Expert
Community Expert
October 8, 2024

You don't need a script or thin space.
Create a character style that only uses the ‘No Break’ attribute.
In the paragraph style used for your text, add a GREP style that applies the ‘No Break’ style to the words ‘N Name’.
You'll never forget these words again.

 

Acrobate du PDF, InDesigner et Photoshopographe
jmlevy
Community Expert
Community Expert
October 8, 2024

Hi @JR Boulay since the OP asks for a thin space, I assume that the GREP style needs more that a no break attribute, but also a 50 % horizontal scale.

jmlevy
Community Expert
Community Expert
October 8, 2024

Depending the actual name of the company, you could “fake” a thin space using a GREP style.