• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Oct 08, 2024 Oct 08, 2024

Copy link to clipboard

Copied

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>

TOPICS
Experiment , Feature request , Scripting , UXP Scripting

Views

207

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Oct 08, 2024 Oct 08, 2024

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

Screenshot 2024-10-08 at 21.40.45.png

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.propertie
...

Votes

Translate

Translate
Community Expert , Oct 08, 2024 Oct 08, 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.

Votes

Translate

Translate
Community Expert ,
Oct 08, 2024 Oct 08, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 08, 2024 Oct 08, 2024

Copy link to clipboard

Copied

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.

 

Capture_2410081218.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 08, 2024 Oct 08, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 08, 2024 Oct 08, 2024

Copy link to clipboard

Copied

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

Screenshot 2024-10-08 at 21.40.45.png

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.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 08, 2024 Oct 08, 2024

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines