Skip to main content
dublove
Legend
Nov 29, 2026 4:57 AM UTC
Answered

What are the forms of parameter passing in doScript?

Hi everyone.

I remember that only when passing multiple references, numbers are needed to represent them, similar to this:

try {
app.doScript(main, ScriptLanguage.JAVASCRIPT, [a,b,c], UndoModes.ENTIRE_SCRIPT, 'main');
} catch (e) {
}
function main(t) {
var a=t[0],b=t[1],c=t[2];
}

Can't it be like this? Write directly to main().

try {
app.doScript(main, ScriptLanguage.JAVASCRIPT, [a,b,c], UndoModes.ENTIRE_SCRIPT, 'main');
} catch (e) {
}
function main([a,b,c]) {
}

If I only pass one parameter, I remember not needing to use the array [] so troublesome.
Did I make a mistake?

It doesn't work like this:

try {
app.doScript(main, ScriptLanguage.JAVASCRIPT, t, UndoModes.ENTIRE_SCRIPT, 'main');
} catch (e) {
}
function main(t) {

}

What are the forms of expression?

Thank you very much.

    CORCTON
    CORCTONCorrect answer
    Community Expert
    Nov 29, 2026 6:04 AM UTC

    Hi dublove — your memory is right, and your first version is the only form that works:

     

    1. doScript's third parameter must always be an Array, and main() receives that whole array as its single argument. So this is correct:

    app.doScript(main, ScriptLanguage.JAVASCRIPT, [a, b, c], UndoModes.ENTIRE_SCRIPT, 'main');

    function main(t) { var a = t[0], b = t[1], c = t[2]; }

     

    2. function main([a, b, c]) {} does not work in ExtendScript — the engine is based on ECMAScript 3, which has no destructuring in parameter lists, so that is a syntax error there.

     

    3. One parameter still has to go in an array, as you found:

    app.doScript(main, ScriptLanguage.JAVASCRIPT, [t], UndoModes.ENTIRE_SCRIPT, 'main');

    function main(args) { var t = args[0]; }

     

    One note: if main() is in the same script, you don't need doScript to pass normal parameters — just call main(a, b, c) directly. doScript is for running the function as its own undoable step (or running a separate script file or string).

    2 replies

    CORCTON
    Community Expert
    CORCTONCommunity ExpertCorrect answer
    Community Expert
    Nov 29, 2026 6:04 AM UTC

    Hi dublove — your memory is right, and your first version is the only form that works:

     

    1. doScript's third parameter must always be an Array, and main() receives that whole array as its single argument. So this is correct:

    app.doScript(main, ScriptLanguage.JAVASCRIPT, [a, b, c], UndoModes.ENTIRE_SCRIPT, 'main');

    function main(t) { var a = t[0], b = t[1], c = t[2]; }

     

    2. function main([a, b, c]) {} does not work in ExtendScript — the engine is based on ECMAScript 3, which has no destructuring in parameter lists, so that is a syntax error there.

     

    3. One parameter still has to go in an array, as you found:

    app.doScript(main, ScriptLanguage.JAVASCRIPT, [t], UndoModes.ENTIRE_SCRIPT, 'main');

    function main(args) { var t = args[0]; }

     

    One note: if main() is in the same script, you don't need doScript to pass normal parameters — just call main(a, b, c) directly. doScript is for running the function as its own undoable step (or running a separate script file or string).

    Translate
    dublove
    dubloveAuthor
    Legend
    Nov 29, 2026 7:06 AM UTC

    Hi ​@CORCTON 

    One note: if main() is in the same script, you don't need doScript to pass normal parameters — just call main(a, b, c) directly. doScript is for running the function as its own undoable step (or running a separate script file or string).

    What does this mean? for example:

    Translate