Just recapping, you build a dialog by first building a list of controls, then passing them to the main handler to add them to an alert and show it, and then return any results. And to make the geometry easier, you start building the controls from the bottom up, so that as each one returns its top coordinate, you can use that as the basis of the bottom coordinate of the next one.
The first example will be an alert containing a labelled set of radio buttons, a labeled popup, then a checkbox, a labeled path control, a rule, an entry field with a side label, and a muti-line entry field with a label on top. The code should start like this:
use theLib : script "Dialog Toolkit" -- name of script library file use scripting additions
tell theLib its checkForMainThread()
If you are running Yosemite, you can skip the library lines and run the code directly. The checkForMainThread() call isn't absolutely required, but you're like to soon regret leaving it out if you do.
Starting at the bottom, the deep muti-line entry field with label on top is built like this:
set {instructionsField, instructionsLabel, theTop} to its makeTopLabeledTextField:"" placeholderText:"Extra instructions go here" leftInset:0 bottom:0 theWidth:400 extraHeight:60 label:"Instructions"
So it starts off with no text, it's 400 points wide, it's 60 points deeper than a single-line field, and text wraps in it.
The second field is created similarly, only this time we pass the top of the previous control, plus a bit of space, ans the bottom. We also pass the user name as the initial text.
set {operatorField, operatorLabel, theTop, fieldLeft} to its makeSideLabeledTextField:(short user name of (system info)) placeholderText:"Your name" leftInset:0 bottom:(theTop + 8) totalWidth:400 label:"Operator:" fieldLeft:0
The rule is simple, with a bit more space:
set {theRule, theTop} to its makeRuleAt:(theTop + 12) leftInset:0 theWidth:400
Then come the path control, checkbox, popup and matrix:
set {thePathControl, pathLabel, theTop} to its makeTopLabeledPathControlFor:(POSIX path of (path to documents folder)) leftInset:0 bottom:(theTop + 12) theWidth:400 popsUp:false label:"Choose or drag the file here:" set {theCheckbox, theTop, newWidth} to its makeCheckbox:"One side only" leftInset:0 bottom:(theTop + 8) maxWidth:400 initialState:false set {colorPopup, popupLabel, theTop} to its makeLabeledPopup:{"Red", "Green", "Blue"} leftInset:0 bottom:(theTop + 8) maxWidth:400 popupWidth:100 label:"Choose color:" popupLeft:150 set {jobMatrix, matrixLabel, theTop, matrixLeft} to its makeLabeledMatrix:{"Press 1", "Press 2", "Press 3"} leftInset:0 bottom:(theTop + 8) maxWidth:400 label:"Job is for:" matrixLeft:0 isVertical:false
Then a list of all the controls is made, and finally passed to the main handler:
set allControls to {instructionsField, instructionsLabel, operatorField, operatorLabel, theRule, thePathControl, pathLabel, theCheckbox, colorPopup, popupLabel, jobMatrix, matrixLabel} set {buttonName, suppressedState, controlsResults} to (its displayAlert:"Send for output" message:"" asStyle:2 buttons:{"Cancel", "OK"} suppression:false givingUpAfter:120.0 AVWidth:400 AVHeight:theTop AVControls:allControls) end tell
But before you hit Run, remember the warning: this must be run in the foreground. In Script Editor, you run a script in the foreground by holding the control key when running it, or pressing control-command-R. You can see the Run command change names in the Script menu when you hold down the control key. In ASObjC Explorer you check the 'Run in foreground' checkbox at the bottom of the script window. The checkForMainThread() call will stop you from crashing your editor by forgetting this.
Now you can finally test it. Try changing the various parameters, and see what happens.
As I said at the beginning, this is only lightly tested, so if you strike any oddities, please post here so I can amend the code. At some stage I'll post it all together somewhere.
|