Is there a way to make a dialog box with multi-line text resize dynamically?

I built a small app that asks for some input and depending on what you enter, the number of output lines will vary. Is there anyway to have the dialog box dynamically adjust?


Thanks,

Nick

Posted on Jul 30, 2011 11:23 AM

Reply
9 replies

Jul 30, 2011 2:34 PM in response to pibod

If you're using the standard display dialog command then there's nothign dynamic about it - it won't expand as the user types. However, you might be able to fake it out if you know how much you expect the user to enter - the initial dialog size is based on the dialog text and default answer parameters, so if you expect the user to enter three lines of input then you can preset the dialog to that size via something like:


display dialog "Enter some text:" default answerreturn & return & return


The fact that your default answer is three blank lines forces the input field to be three lines high. Is that sufficient for your needs?


If you want more than that you'll need to migrate to AppleScript Studio and/or AppleScriptObjC, depending on your OS version. These enable full-blown GUI applications, with all the goodies you can do with a 'regular' app/GUI, but also with additional complexity on the script side.

Jul 31, 2011 11:53 AM in response to Camelot

Thanks for the input everyone. Actually, maybe the better question is if there's a better way to do this--essentially I have a small bash script that pulls weather info from the web. It can take any number of inputs--so I could say "metar kowd" or metar "kowd kack kmvy kbos". The amout of output will vary depending on how many inputs I put in. I have it wrapped in an automator workflow such that it pops up a dialog box asking for the input, and then displays the output in a dialog box. The problem is that the dialog box seems to be limited to 4 lines. See the attahed picture, you can see that the last line is getting cut off and anything below that is lost.


Maybe there's something other than a dialog box I can use for the output?


Thx,

NickUser uploaded file

Jul 31, 2011 2:53 PM in response to pibod

There's something amiss with your script/system. The initial dialog should always be sized to accommodate the input data (eiither the text to display, or the 'default answer' as I demonstrated above).


Indeed, if you run this script which picks 100 random words from a list you'll see the dialog does, indeed, resize to accommodate all the text.


set theWords to {"apple", "banana", "cantaloupe", "dates", "eggplant", "fig", "grapes", "habanero", "jujube", "kalamata olive"}

set theText to ""

repeat 100 times

set theText to theText & some item of theWords & space

end repeat

display dialogtheText


User uploaded file


When you said 'dynamically' I assumed you meant after the initial display and in response to the user's input.


Maybe if you posted your script someone could spot a flaw.

Jul 31, 2011 2:51 PM in response to pibod

In applescript or automator you can use Choose From List - this will present you with a predefined list of items, where you can select any number of them to send back to the script. In other words, you run the script, see the dialog, select (say) kowd and kmvy, and the script/workflow appends those to your unix command. You could also rig up something using a one-line text box - enter delimited text like "kowd, kmvy, bkos" and have the workflow split the text, but choose from list will make it so you don't have to remember or type out the code words for each run.


If you want to use applescript, you can even have the script remember the last combination you selected and set it as the default - just save the output in a property then feed that property back in as a default value - but that may be unnecessarily tricky.

Jul 31, 2011 5:47 PM in response to pibod

Strangely enough, this seems to be an issue with Automator.


If you run the script as 'pure' AppleScript (via Script Editor), you don't have this problem and the dialog sizes accordingly. I'd almost classify it as a bug in Automator.


For now your workaround may be to just write this in AppleScript (which, IMHO is easier/better, anyway):


set theTxt to do shell script "/Users/njlarkin/METAR/metar"

display dialogtheTxt


I'm just not sure how you're getting the input values from the user....

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Is there a way to make a dialog box with multi-line text resize dynamically?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.