Skip to main content
emily15D5
Participant
October 6, 2026
Answered

Script to align 2 objects vertical + horizontal with one click?

  • October 6, 2026
  • 3 replies
  • 39 views

I would like to be able to select two objects (usually a text frame and a shape) and align by BOTH vertical and horizontal centers with one click and/or keyboard shortcut. I letter comics which involves centering text over a speech balloon/text box repeatedly. Having to align twice each time a change is made to either one is really inefficient. 


This user seemed to be looking for the same exact solution as me, and posted a solution, but InDesign doesn’t recognize the script when I save the text as a JSX file. It is from several years ago so I don’t know if my attempt to use the script is incorrect, or if it’s outdated somehow. 


If someone knows a script that can do this, or can help me troubleshoot using the one above, that would be amazing!

    Correct answer CORCTON34033231

    Hi Emily 🙂

     

    You don't need that long script — a two-line script does exactly this (this is the short version suggested by an expert in the thread you linked):

     

    app.activeDocument.align(app.selection, AlignOptions.HORIZONTAL_CENTERS);

    app.activeDocument.align(app.selection, AlignOptions.VERTICAL_CENTERS);

     

    How to use it:

     

    1. Paste those two lines into a plain-text editor and save the file with a .jsx extension (for example CenterAlign.jsx). Plain text matters — if the file is saved as rich text, or ends up as .jsx.txt, InDesign won't recognize it, which is very likely what happened with the script you tried.

    2. In InDesign, open Window > Utilities > Scripts, right-click the User folder and choose Reveal in Explorer/Finder, and put the .jsx file in the Scripts Panel folder. It will then appear in the Scripts panel.

    3. Select your text frame and the balloon/shape, and double-click the script — both centers align in one go.

    4. For a keyboard shortcut: Edit > Keyboard Shortcuts, set Product Area to Scripts, select your script and assign the shortcut you want.

     

    Hope that speeds up the lettering!

    3 replies

    emily15D5
    emily15D5Author
    Participant
    October 7, 2026

    That works perfectly! Thanks for the tip on ensuring the script file was in plain text as well. This is exactly what I wanted to figure out, thank you so much :) 

    CORCTON34033231
    Community Expert
    CORCTON34033231Community ExpertCorrect answer
    Community Expert
    October 7, 2026

    Hi Emily 🙂

     

    You don't need that long script — a two-line script does exactly this (this is the short version suggested by an expert in the thread you linked):

     

    app.activeDocument.align(app.selection, AlignOptions.HORIZONTAL_CENTERS);

    app.activeDocument.align(app.selection, AlignOptions.VERTICAL_CENTERS);

     

    How to use it:

     

    1. Paste those two lines into a plain-text editor and save the file with a .jsx extension (for example CenterAlign.jsx). Plain text matters — if the file is saved as rich text, or ends up as .jsx.txt, InDesign won't recognize it, which is very likely what happened with the script you tried.

    2. In InDesign, open Window > Utilities > Scripts, right-click the User folder and choose Reveal in Explorer/Finder, and put the .jsx file in the Scripts Panel folder. It will then appear in the Scripts panel.

    3. Select your text frame and the balloon/shape, and double-click the script — both centers align in one go.

    4. For a keyboard shortcut: Edit > Keyboard Shortcuts, set Product Area to Scripts, select your script and assign the shortcut you want.

     

    Hope that speeds up the lettering!

    emily15D5
    emily15D5Author
    Participant
    October 7, 2026

    whoops now I think I’ve gone and replied to the whole thread by accident - thanks so much again for the help!