Skip to main content
August 5, 2015
Answered

Is there a character limit for prompt()?

  • August 5, 2015
  • 1 reply
  • 1694 views

I came across a comment on another website to the effect that the global method prompt() will crash PhotoShop if the user types more than 255 characters in the text field. From my brief experience today, I would say that the same limit applies to InCopy and InDesign as well. Has anyone else encountered this?

I guess the next step would be to use ScriptUI to create a text-entry dialog.

This topic has been closed for replies.
Correct answer Jongware

... here is a quick version of a Larger Prompt dialog. I just tested and could paste 29,721 characters into it. No idea where that limit comes from.

text = largerPrompt ("Hello there!");

alert ("you entered "+text.length+" characters");

exit();

function largerPrompt (title)

{

    var w = new Window("dialog", title);

    var textfield = w.add ("edittext", [0, 0, 500, 300], "", {multiline: true});

    textfield.text = "Paste or type text in here\rUse Ctrl+Tab to insert a Tab, Ctrl+Enter to insert a Hard return";

    textfield.active = true;

    with (w.add("group"))

    {

        orientation = "row";

        add ("button", undefined, "OK");

        add ("button", undefined, "Cancel");

    }

    if (w.show()==2)

        return null;

    return textfield.text;

}

1 reply

Jongware
Community Expert
Community Expert
August 5, 2015

‌I've never encountered such a limit ... but maybe it's because a prompt is for, well ... your basic prompting. Entering more than 200 characters is stretching its intended use The good news is a simple ScriptUI dialog can do the same thing, and you get a multi-line edit box for free. I cannot say anything on a maximum of text that can be entered into it, but I've pasted at least several thousands of characters into one.

Jongware
Community Expert
JongwareCommunity ExpertCorrect answer
Community Expert
August 6, 2015

... here is a quick version of a Larger Prompt dialog. I just tested and could paste 29,721 characters into it. No idea where that limit comes from.

text = largerPrompt ("Hello there!");

alert ("you entered "+text.length+" characters");

exit();

function largerPrompt (title)

{

    var w = new Window("dialog", title);

    var textfield = w.add ("edittext", [0, 0, 500, 300], "", {multiline: true});

    textfield.text = "Paste or type text in here\rUse Ctrl+Tab to insert a Tab, Ctrl+Enter to insert a Hard return";

    textfield.active = true;

    with (w.add("group"))

    {

        orientation = "row";

        add ("button", undefined, "OK");

        add ("button", undefined, "Cancel");

    }

    if (w.show()==2)

        return null;

    return textfield.text;

}

August 6, 2015

Thanks so much... I went ahead with the built-in prompt() and put the chore of creating a scriptUI version on my round-to-it list, but this just plugs and plays.