Skip to main content
dublove
Legend
September 23, 2026
Answered

How to use a script to obtain the paragraph style of the first paragraph of the selected text?

  • September 23, 2026
  • 3 replies
  • 26 views

Hello everyone.

I want to obtain the paragraph style of the first paragraph of the selected text, and then obtain the leading (the original unchanged leading ) from the paragraph style.

The premise is that the name and grouping of the paragraph style are uncertain.

 

    Correct answer CORCTON34033231

    Hi! When text is selected, app.selection[0] is a Text object, so you can get its first paragraph directly:

     

    var sel = app.selection[0];

    if (sel instanceof Text && sel.paragraphs.length > 0) {

        var pStyle = sel.paragraphs[0].appliedParagraphStyle;

        $.writeln("Style: " + pStyle.name);

        $.writeln("Leading: " + pStyle.leading);

    }

     

    A couple of notes:

     

    - sel.paragraphs[0] is the paragraph containing the start of the selection — this works even if the selection starts mid-paragraph or is just an insertion point.

    - ParagraphStyle.leading gives you the leading defined in the style: either a point value (e.g. "14.4 pt") or Leading.AUTO when the style uses auto-leading. If it's auto and you need the effective value, read pStyle.autoLeading (the percentage) and multiply it by the type size.

    - If the user selects a whole text frame instead of text, use sel.parentStory.paragraphs[0].appliedParagraphStyle instead.

    3 replies

    CORCTON34033231
    Community Expert
    CORCTON34033231Community ExpertCorrect answer
    Community Expert
    September 23, 2026

    Hi! When text is selected, app.selection[0] is a Text object, so you can get its first paragraph directly:

     

    var sel = app.selection[0];

    if (sel instanceof Text && sel.paragraphs.length > 0) {

        var pStyle = sel.paragraphs[0].appliedParagraphStyle;

        $.writeln("Style: " + pStyle.name);

        $.writeln("Leading: " + pStyle.leading);

    }

     

    A couple of notes:

     

    - sel.paragraphs[0] is the paragraph containing the start of the selection — this works even if the selection starts mid-paragraph or is just an insertion point.

    - ParagraphStyle.leading gives you the leading defined in the style: either a point value (e.g. "14.4 pt") or Leading.AUTO when the style uses auto-leading. If it's auto and you need the effective value, read pStyle.autoLeading (the percentage) and multiply it by the type size.

    - If the user selects a whole text frame instead of text, use sel.parentStory.paragraphs[0].appliedParagraphStyle instead.

    dublove
    dubloveAuthor
    Legend
    September 23, 2026

    Hi CORCTON34033231

    Thank you.
    I forgot the applied Paragraph Style again.
    I'm a bit overheated.