Dialog Toolkit Plus - how to coerce text input to variable?

Clearly I am out of my depth and should not even try to do what I am trying, but if there’s an easy answer to this question. I’ll be very grateful. After a great deal of trial and error (mostly error) I created this dialog using Dialog Toolkit Plus:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use script "Dialog Toolkit Plus" version "1.1.0"

set accViewWidth to 300
set {theButtons, minWidth} to create buttons {"Cancel", "OK"} button keys {"", ""} default button 2 cancel button 1
set {keyField, keyLabel, theTop, fieldLeft} to create side labeled field "" placeholder text " " bottom 0 total width accViewWidth label text "Key (default [space]; try 'e'):         " field left 0
set {depthField, depthLabel, theTop, fieldLeft} to create side labeled field "" placeholder text "6" bottom (theTop + 14) total width accViewWidth label text "Search depth (default 6):               " field left 0
set {maxField, maxLabel, theTop, fieldLeft} to create side labeled field "" placeholder text "12" bottom theTop + 12 total width accViewWidth label text "Max password length (default 12):" field left 0
set {minimField, minimLabel, theTop, fieldLeft} to create side labeled field "" placeholder text "3" bottom theTop + 10 field left 0 label text "Min password length (default 3):   " total width accViewWidth
set {headingLabel, theTop} to create label "I will use these settings for decrypting; change only if defaults fail." bottom theTop + 14 max width accViewWidth aligns left aligned
set {buttonName, controlsResults} to display enhanced window "Settings" acc view width accViewWidth acc view height theTop acc view controls {headingLabel, keyField, keyLabel, depthField, depthLabel, maxField, maxLabel, minimField, minimLabel} buttons theButtons active field minimField initial position {10, 10} with align cancel button

What I can’t figure out is something that ought to be obvious: how to get the user’s input from the dialog into a variable? Whenever I try to set a variable to (for example) “depthField” I get an error message saying that nsTextString - or its stringValue() when I tried using that - can’t be converted to text.

Apologies for wasting bandwidth on a question that anyone who knows anything AppleScript should be able to answer

To answer my own question

set depthNum to item 4 of controlsResults

I really need to learn to how to use SD and save myself much agony - the answer was right there in the right panel.

1 Like
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use script "Dialog Toolkit Plus" version "1.1.0"

set accViewWidth to 300
set {theButtons, minWidth} to create buttons {"Cancel", "OK"} button keys {"", ""} default button 2 cancel button 1
set {keyField, keyLabel, theTop, fieldLeft} to create side labeled field "" placeholder text " " bottom 0 total width accViewWidth label text "Key (default [space]; try 'e'):         " field left 0
set {depthField, depthLabel, theTop, fieldLeft} to create side labeled field "" placeholder text "6" bottom (theTop + 14) total width accViewWidth label text "Search depth (default 6):               " field left 0
set {maxField, maxLabel, theTop, fieldLeft} to create side labeled field "" placeholder text "12" bottom theTop + 12 total width accViewWidth label text "Max password length (default 12):" field left 0
set {minimField, minimLabel, theTop, fieldLeft} to create side labeled field "" placeholder text "3" bottom theTop + 10 field left 0 label text "Min password length (default 3):   " total width accViewWidth
set {headingLabel, theTop} to create label "I will use these settings for decrypting; change only if defaults fail." bottom theTop + 14 max width accViewWidth aligns left aligned
set {buttonName, controlsResults} to display enhanced window "Settings" acc view width accViewWidth acc view height theTop acc view controls {headingLabel, keyField, keyLabel, depthField, depthLabel, maxField, maxLabel, minimField, minimLabel} buttons theButtons active field minimField initial position {10, 10} with align cancel button

set userResponse to the result

set userButton to item 1 of userResponse

set returnedItems to item 2 of userResponse

Thank you, Ed. Exactly what I needed to get this working correctly.

1 Like

On my side I would use:

set {userButton, {headingLabel, keyValue, keyLabel, depthValue, depthLabel, maxValue, maxLabel, minimValue, minimLabel}} to result
1 Like