Version 2.0.2, July 2016

Dialog Toolkit is an AppleScript scripting library for creating enhanced dialogs. To see its dictionary, drag it over your script editor's icon while holding down the option key, or using the Open Dictionary... command. If you are using Script Debugger 6, just double-click on it and choose Dictionary.

To use it, you should first place it in ~/Library/Script Libraries, a folder you will need to create if you have no script libraries already. To use its commands, you can address it by including the following statement near the beginning of your script:

use script "Dialog Toolkit" version "2.0"

You can also distribute it within script applets and script bundles by creating a folder called Script Libraries in the bundle's /Contents/Resources folder. Under Yosemite and later you can also use the code directly rather than via a library.

The principle here is to take an alert dialog, add as many buttons as you need, and then add what is known as an accessory view, containing any other controls you require. To build the dialog, you create each control, starting from the bottom and working up. This makes it simpler to calculate the geometry, because coordinates are calculated from bottom to top. 

So for each control you provide a "bottom" value -- starting with 0 for the one that will appear at the bottom -- and the command that makes the control will include a "top" value in its result. You then use this value, plus whatever space you wish to put between the controls, as the "bottom" parameter for the control that appears above it.

Once you have created the controls, you call the display enhanced alert command, and the result includes the new values of the controls.

The library has two utility commands:

max width for labels

One of the features of the controls is that you can align them vertically, with labels ranged right next to them. To make this work, you need to have the controls far enough across to fit the longest label. This command can be used calculate the width of the longest label, so that you can position controls properly.

create rule

This can be used to add rules, to separate groups of controls.

The  commands are all documented in the scripting dictionary. All of them return several values, including the Y-coordinate of the top of the control. You can use this in turn to set the position of the next control, and so on.

The result values differ, depending on the control. Checkboxes return true or false, depending on their state; fields return the entered text; popups return the title of the selected item; matrixes return the title of the selected radio button; and path controls return the represented POSIX path.

Version 2.0 changes

* No longer includes non-terminology handlers.

* Changes information/critical/warning alert types to information alert/critical alert/warning alert.

* No longer requires main thread.

Version 2.0.1 changes

The 'label text' type for the 'create labeled checkbox' and 'create labeled popup' commands was wrongly given as integer rather than text in 2.0.

Do not run scripts that use this library in versions of Script Debugger earlier than 6.0.

Dialog Toolkit is copyright ©2014-16, Shane Stanley <sstanley@myriad-com.com.au>. It may be freely distributed and copied. If you modify it, please rename the modified version to avoid clashes. You use it entirely at your own risk. Feedback is welcome.