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

Script equivalent of Indesign Command

Enthusiast ,
Mar 13, 2025 Mar 13, 2025

Hi

I am looking for a script to carry out following command in Indesign. 

Ctrl + Alt + \     and    Ctrl+Alt+Shift+\   => to increase word space

Ctrl + Alt + Bksp     and    Ctrl+Alt+Shift+Bksp  => to decrease word space 

from selected text. Actually I need an interface where I can change the values and see the result live in the text.

 

Thanks

TOPICS
How to , Scripting
1.7K
Translate
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 , Mar 14, 2025 Mar 14, 2025

Hi @Bedazzled532, I have written a script that may help you. Let me know what you think. For instructions, read the script documentation below.

 

Note that it doesn't change "word spacing" per se, because that is a property of a *paragraph*, so instead this script targets the first space after a word boundary and sets its tracking value. To ensure that things don't get too messy, the script will set every word space to the same amount each time you click one of the buttons. I think this will wor

...
Translate
Community Expert , Mar 14, 2025 Mar 14, 2025

Hi @Bedazzled532 I will update the script above with some extra buttons and also some improvements, such as better handling of Undo.

- Mark

Translate
Enthusiast ,
Mar 13, 2025 Mar 13, 2025

This is not working. Says wordSpacing does not exist. I have taken a value of 200 just for testing purpose:

    var selection = app.selection;

    if (selection.length > 0 && selection[0] instanceof Text) {
        var textRange = selection[0];
        textRange.wordSpacing += 200;
    } else {
        alert("Please select some text first.");
    }
Translate
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 ,
Mar 13, 2025 Mar 13, 2025

Because thete is no "wordSpacing" property. 

 

ChatGPT? 

 

It would be rather kerningValue - but not for the whole text. 

 

Translate
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
Enthusiast ,
Mar 13, 2025 Mar 13, 2025

@Robert at ID-Tasker Yes chatgpt. I have scratched all my hairs and not able to imitate this command using script. Yes kerning value does not work for whole text.

If I select the whole text and then run ctrl+alt+\   this increases the space between words nicely. I am not able to get this.

Translate
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 ,
Mar 13, 2025 Mar 13, 2025

Yes, script would've to be more "selective". 

 

What's wrong with using those shortcuts - manually? 

 

Translate
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
Enthusiast ,
Mar 13, 2025 Mar 13, 2025

2000 pages text. Manually will be difficult. At least selecting and increasing/decreasing using interface with live preview would be easy. That is the reason I was looking for a script.

Translate
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 ,
Mar 13, 2025 Mar 13, 2025

OK, but you've said that you want to work on the SELECTION? 

 

Do you have Character / Paragraph Styles applied? 

 

Are you looking to edit specific words / phrases? 

 

Please let me - us - know in more detail what exactly you're looking for. 

 

Translate
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
Enthusiast ,
Mar 13, 2025 Mar 13, 2025

This screenshot might help. The matter in green box is Arabic. The sentence ends in a circle with number inside it. The matter below that in white box is its translation in urdu language. I am trying to match both the circles. The screenshot you see, I hve done it manually which is taking lot of time. Maybe a script can do better.

Translate
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 ,
Mar 13, 2025 Mar 13, 2025

Haven't you posted about that already? A few months ago? 

 

Yeah, script - or rather something more advanced - could help you significantly. 

 

Translate
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
Enthusiast ,
Mar 13, 2025 Mar 13, 2025
Yes i think so. I don't remember properly. I was working on it few months
back then left working on it. This time i hv to finish it off asap.
Translate
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 ,
Mar 13, 2025 Mar 13, 2025

Just a couple of questions for my edification...

Are the frames for each language discrete or do they thread? Is each one a complete paragraph? Which composer are you using?

I ask this because I wonder what's going to happen downstream as you adjust word spacing if this is flowing text.

Translate
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 ,
Mar 13, 2025 Mar 13, 2025

@Peter Spier

 

Those are two separate Stories.

 

Translate
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 ,
Mar 13, 2025 Mar 13, 2025

@Robert at ID-Tasker  I understand that there are two separate stories for the two languages, so perhaps I wasn't clear in what I'm asking. Is every frame on the page a separate story, or do the two languages thread down the page, and more importantly, to the next page.

Translate
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 ,
Mar 13, 2025 Mar 13, 2025
Translate
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
Enthusiast ,
Mar 13, 2025 Mar 13, 2025

They are two separate stories threaded in their own frames. Arabic with arabic and Urdu with urdu. Both have separate paragrah styles applied to them. I am changing space using the command of the white threaded text frames only to match both the circes.

Translate
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 ,
Mar 13, 2025 Mar 13, 2025

@Bedazzled532 so do the threaded stories continue on multiple pages?

 

By way of explanation for this question, when I did newspaper work I would frequently use word space adjustments to gain or lose a line in a long paragraph to make the copy fit the column length. I'm wondering if what you are doing is risking moving words from one frame to another for only one language, making your imbalance worse downstream someplace. I'm not saying you shouldnt be doing this, just curious if this might be a problem and if you've thought about it.

Translate
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 ,
Mar 13, 2025 Mar 13, 2025

I hope you won't mind @Bedazzled532 for posting some sreenshots?

 

@Peter Spier - it looks like this - two TFs on two separate layers - with big line spacing:

 

RobertatIDTasker_0-1741890090946.png

 

Translate
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
Enthusiast ,
Mar 13, 2025 Mar 13, 2025
Translate
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 ,
Mar 13, 2025 Mar 13, 2025

From your old file @Bedazzled532:

 

RobertatIDTasker_0-1741890857976.png

 

As long as someone can maybe create a better GREP expression - perfectly doable.

 

My solution isn't free - but I can give you access to the full version for free for a few days - you're working on Windows anyway.

 

Translate
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
Enthusiast ,
Mar 13, 2025 Mar 13, 2025

@Robert at ID-Tasker Thanks Robert thats very nice of you.

Translate
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 ,
Mar 13, 2025 Mar 13, 2025

@Bedazzled532 

 

Still have fonts from January 😉

 

RobertatIDTasker_0-1741891213183.png

 

Looks like you went for separate TFs? Still - not a problem.

 

Translate
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 ,
Mar 13, 2025 Mar 13, 2025

@Bedazzled532 just re-read your last post and I missed that you are making adjustments in only one of the threads. I think that probably mitigates the risk.

Translate
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
Enthusiast ,
Mar 13, 2025 Mar 13, 2025

@Peter Spier Yes I am making changes in only one thread.

Translate
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 ,
Mar 14, 2025 Mar 14, 2025

Hi @Bedazzled532, I have written a script that may help you. Let me know what you think. For instructions, read the script documentation below.

 

Note that it doesn't change "word spacing" per se, because that is a property of a *paragraph*, so instead this script targets the first space after a word boundary and sets its tracking value. To ensure that things don't get too messy, the script will set every word space to the same amount each time you click one of the buttons. I think this will work best.

 

In RTL text like Arabic, I think maybe the buttons should go RTL also, so I've put a setting in to set that. It is ON by default.

 

Let me know how it works.

- Mark

 

Screenshot 2025-03-14 at 21.13.07.png

 

 

 

 

/**
 * @file Word Spacer.js
 *
 * Shows a modeless palette with 7 buttons.
 *
 * To use:
 * 1. Invoke this Script in the Scripts Panel, if palette is not already open.
 * 2. Select some text
 * 3. Click one of the buttons
 *    - the center button will reset the word spacing
 *    - the other buttons will increment or decrement the word spacing
 *
 * Notes:
 *    - if `settings.RTL` is true then the order of the buttons will
 *      be reversed, to work better with RTL text systems.
 *    - you can customize the `settings.spacings` to suit your preferences.
 *    - the center `settings.spacings` is the "reset" value.
 *
 * @author m1b
 * @version 2025-03-14
 * @discussion https://community.adobe.com/t5/indesign-discussions/script-equivalent-of-indesign-command/m-p/15209276
 */

//@targetengine "wordSpacer"

(function () {

    var settings = {

        /**
         * if true, will reverse the button spacings
         * to work better with RTL text systems
         */
        RTL: true,

        /**
         * the spacing values, smallest to largest,
         * in the font's em-units
         *   - the center value is the "reset" value
         *   - the number of spacings will also effect
         *     how many buttons appear in the UI, so if
         *     spacings are [-50, -10, -1, 0, 1, 10, 50]
         *     then only 7 buttons will appear
         */
        spacings: [-250, -50, -10, -1, 0, 1, 10, 50, 250],

        /**
         * the button labels in the UI
         */
        buttonLabels: ['<<<<', '<<<', '<<', '<', '0', '>', '>>', '>>>', '>>>>'],

    };

    if (settings.RTL)
        settings.spacings.reverse();

    // UI button sizes
    var buttonSizes = [[52, 46], [46, 46], [40, 40], [35, 35], [135, 35], [35, 35], [40, 40], [46, 46], [52, 46],];

    // make the buttonLabels and sizes match the spacings
    while (settings.buttonLabels.length > settings.spacings.length) {
        settings.buttonLabels.pop();
        settings.buttonLabels.shift();
        buttonSizes.pop();
        buttonSizes.shift();
    }

    var doc = app.activeDocument,
        len = settings.spacings.length,
        middle = Math.floor(len / 2);

    // make the palette
    var w = new Window("palette", "Word Spacer"),
        buttons = w.add("Group {orientation:'row', alignment:['center','top'], margins:[0,0,0,0]}");


    // make the buttons
    for (var i = 0; i < len; i++) {

        (buttons.add("Button {text:'" + settings.buttonLabels[i] + "',preferredSize:[" + buttonSizes[i] + "]}"))
            .onClick = (middle === i)
                ? resetter(settings.spacings[i])
                : incrementer(settings.spacings[i]);

    }

    var resetButton = buttons.children[middle];

    w.show();

    function incrementer(n) {
        return function () {
            resetButton.text = wordSpace({
                text: doc.selection[0],
                increment: n,
            })
        };
    };

    function resetter(n) {
        return function () {
            resetButton.text = wordSpace({
                text: doc.selection[0],
                base: n,
            })
        };
    };

    /**
     * Changes the tracking of spaces in the `text`.
     * @author m1b
     * @version 2025-03-14
     * @param {Object} options
     * @param {Text} options.text - the text to change.
     * @param {Number} [options.base] - the absolute value to apply to spaces tracking.
     * @param {Number} [options.increment] - the change to apply to spaces tracking.
     * @returns {Number} - the tracking value applied.
     */
    function wordSpace(options) {

        var base = options.base,
            increment = options.increment;

        if (
            0 === base
            && 0 === increment
        )
            return;

        var text = doc.selection[0];

        if ('function' !== typeof text.findGrep)
            return;

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

        app.findGrepPreferences.findWhat = '\\s(?=\\b)';

        var spaces = text.findGrep();

        if (0 === spaces.length)
            return;

        if (undefined == base)
            base = spaces[0].insertionPoints[-1].kerningValue;

        var kerning = base + (increment || 0);

        app.doScript(function () {

            // do the word spacing
            for (var i = spaces.length - 1; i >= 0; i--)
                spaces[i].insertionPoints[-1].kerningValue = kerning;

        }, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set Word Spacing');

        return kerning;

    };

})();

 

Edit 2025-03-14: improved script documentation.

Edit 2025-03-14: changed spacing method so that it is compatible with Indesign's method.
Edit 2025-03-15: added an extra increment button, both ways, added easier to edit button labels, and improved the script's interaction with undo.

Translate
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 ,
Mar 14, 2025 Mar 14, 2025

@m1b

 

Out of curiosity - won't the effect be the same as hitting those original keyboard shortcuts?

 

Translate
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