Skip to main content
dublove
Legend
October 16, 2026
Answered

How to choose one line more (or less) than before?

I have selected some text (such as 9 lines) and I want to use a script to adjust the line spacing.
After adjusting the line spacing with the script, how can I add one more line (such as 10 lines) than before?

var d = app.activeDocument;
var item = app.selection[0];
oLinesNum = item.lines.length;
//do something
item.texts[0].leading = 16 - 1;

//Retrieve the selection with one less row
//like this
app.select(oLinesNum + 1)

 

    Manan JoshiCorrect answer
    Community Expert
    October 16, 2026

    Try the following. Remove your last line and use this instead

    var sel = app.selection[0];
    var sidx = sel.characters[0].index;
    var eidx = sel.characters[-1].index;
    var nLine = sel.parent.characters[eidx + 1].lines;
    if(nLine && nLine.length > 0 && nLine[0] != sel.lines[-1]){
    var neIdx = eidx + nLine[0].characters.length;
    app.select(sel.parent.characters.itemByRange(sidx, neIdx))
    }

     

    -Manan

    2 replies

    Manan JoshiCommunity ExpertCorrect answer
    Community Expert
    October 16, 2026

    Try the following. Remove your last line and use this instead

    var sel = app.selection[0];
    var sidx = sel.characters[0].index;
    var eidx = sel.characters[-1].index;
    var nLine = sel.parent.characters[eidx + 1].lines;
    if(nLine && nLine.length > 0 && nLine[0] != sel.lines[-1]){
    var neIdx = eidx + nLine[0].characters.length;
    app.select(sel.parent.characters.itemByRange(sidx, neIdx))
    }

     

    Translate
    -Manan
    dublove
    dubloveAuthor
    Legend
    October 16, 2026

    Hi Manan Joshi

    Thank you very much.
    A great example.

    Translate