The script below won’t progress past log 2, halting after log 1. It errors with the message in the title of this topic. Why? macOS Mojave.
use scripting additions
use script "Dialog Toolkit Plus"
set MaxLabelWidthParams to {}
set TheExampleTrack to "Paganini Etude No.4, in E Major (Vivo) - Paganini-Liszt"
set InfoText to "Sample: " & TheExampleTrack & "\r\rSpecify the sample's substring to be replaced." & return & return & "May be a literal match or a regular expression. \r\rFor a regex match, character classes are supported; POSIX bracket expressions designating character classes, and special characters (prepended by the escape symbol) are to be avoided. Backreferences are introduced with \"$\"."
(*
Compute maxLabelWithValue by populating the variable MaxLabelWidthParams. The variable is a list of text members, on which the command 'max width for labels' calculates the maximal width member.
*)
set end of MaxLabelWidthParams to InfoText
(*
Replace all values and commands below as you see fit.
Done.
*)
set MaxLabelWidthValue to round (max width for labels MaxLabelWidthParams)
my makePrompt()
on makePrompt()
global MaxLabelWidthValue, TheExampleTrack, InfoText
set TextFields to {}
set AccViewWidth to (MaxLabelWidthValue)
set Bottommost to 10
log "1"
set {Field_bottom, labelText, theTop} to create top labeled field bottom Bottommost field width (MaxLabelWidthValue div 3) label text "Replacement string:"
log "2"
set Bottommost to (Bottommost + 2 * (theTop - Bottommost))
set {Field_top, labelText, theTop} to ¬
¬
create top labeled field bottom Bottommost ¬
field width (MaxLabelWidthValue div 3) ¬
label text ¬
"Replaced string:" placeholder text TheExampleTrack
repeat with anObj in {Field_bottom, Field_top}
set this_item to anObj's contents
set end of TextFields to this_item
end repeat
log "3"
display enhanced window ¬
¬
¬
¬
¬
InfoText ¬
acc view width AccViewWidth ¬
acc view height theTop + 10 ¬
acc view controls TextFields
end makePrompt
I started trying to edit your script to make it work, but found it easier to use the Dialog Toolkit commands I have in my clippings to build a new dialog.
What I noticed is that your version did not include buttons, which are required; did not have a first parameter for the fields, also required.
This runs, and if you look closely you should be able to see how to make it work for you.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use script "Dialog Toolkit Plus"
set TheExampleTrack to "Paganini Etude No.4, in E Major (Vivo) - Paganini-Liszt"
set InfoText to "Sample: " & TheExampleTrack & "
Specify the sample's substring to be replaced." & return & return & "May be a literal match or a regular expression.
For a regex match, character classes are supported; POSIX bracket expressions designating character classes, and special characters (prepended by the escape symbol) are to be avoided. Backreferences are introduced with \"$\"."
-->>MaxWidth for labels
set MaxLabelWidthP to max width for labels {InfoText, TheExampleTrack}
--<<MaxWidth for labels
set accViewControls to {}
set controlResults to {}
set accViewWidth to 400
set theBottom to 0
set spacer to 12
set theTop to spacer
--Variables
set buttonList to ¬
{¬
("Cancel"), ¬
("Find"), ¬
("Find & Replace") ¬
}
set windowTitle to "Window title"
set initialPosition to {30, 30}
--Build window buttons
set {theButtons, theWidth} to create buttons buttonList ¬
default button 3 ¬
cancel button 1 ¬
equal widths false ¬
--button keys {textList}
if theWidth > accViewWidth then set accViewWidth to theWidth
-->ACC views go here --Bottom first, top last
--<<Labeled field
set theBottom to (theTop + spacer)
set textInField to InfoText
set placeholderText to InfoText
set labelText to "Label text"
set {theLabeledField, labelFieldLabel, theTop} to ¬
create top labeled field TheExampleTrack ¬
placeholder text TheExampleTrack ¬
left inset 0 ¬
bottom theBottom ¬
field width accViewWidth ¬
extra height spacer ¬
accepts linebreak and tab true ¬
label text labelText
set the beginning of accViewControls to theLabeledField
set the end of accViewControls to labelFieldLabel
-->>Labeled field
--<<Labeled field
set theBottom to (theTop + spacer)
set textInField to InfoText
set placeholderText to InfoText
set labelText to "Label text"
set {theLabeledField, labelFieldLabel, theTop} to ¬
create top labeled field textInField ¬
placeholder text placeholderText ¬
left inset 0 ¬
bottom theBottom ¬
field width accViewWidth ¬
extra height spacer ¬
accepts linebreak and tab true ¬
label text labelText
set the beginning of accViewControls to theLabeledField
set the end of accViewControls to labelFieldLabel
-->>Labeled field
--<<end ACC views
--Display Enhanced window
set accViewHeight to theTop
set {userResponse, controlValues} to ¬
display enhanced window windowTitle ¬
buttons theButtons ¬
acc view width accViewWidth ¬
acc view height accViewHeight ¬
acc view controls accViewControls ¬
initial position initialPosition ¬
with align cancel button
--giving up after 60
--active field 1
Maybe, I’m too tired right now, but no matter how astute, I can’t seem to catch the principal difference between your code and mine, because these top labels slip. It simply displays standard ones. Maybe you have the sharpest eye of us two? What’s broken? I modified the logic a bit and also what text goes to what label.
use scripting additions
use script "Dialog Toolkit Plus"
set MaxLabelWidthParams to {}
set TheExampleTrack to "Paganini Etude No.4, in E Major (Vivo) - Paganini-Liszt"
set InfoText to "Specify the substring to be replaced." & return & return & "May be a literal match or a regular expression. \r\rFor a regex match, character classes are supported; POSIX bracket expressions designating character classes, and special characters prepended by the escape symbol aren't supported. Backreferences are introduced with \"$\"."
(*
Compute maxLabelWithValue by populating the variable MaxLabelWidthParams. The variable is a list of text members, on which the command 'max width for labels' calculates the maximal width member.
*)
set MaxLabelWidthParams to MaxLabelWidthParams & InfoText & TheExampleTrack
(*
Replace all values and commands below as you see fit.
Done.
*)
set MaxLabelWidthValue to round (max width for labels MaxLabelWidthParams)
my makePrompt()
on makePrompt()
global MaxLabelWidthValue, TheExampleTrack, InfoText
set img_dim to 50
set DialImage to (system attribute "HOME") & "/Pictures/Logotypes/iTunes.png"
set TextFields to {}
set AccViewWidth to (MaxLabelWidthValue div 4)
set Bottommost to 20
set {Field_bottom, labelText, theTop} to create top labeled field TheExampleTrack bottom Bottommost field width AccViewWidth label text "Replacement string:"
set Bottommost to (theTop + 50)
set {Field_top, labelText, theTop} to ¬
¬
create top labeled field TheExampleTrack bottom Bottommost ¬
field width AccViewWidth ¬
label text ¬
¬
"Replaced string (sample):"
set {labelText, theTop, _width} to create label InfoText bottom (theTop + 20) max width AccViewWidth control size regular size
set {_Image, theTop} to ¬
create image view DialImage ¬
bottom theTop + 25 ¬
view width img_dim ¬
view height img_dim ¬
left inset (round (AccViewWidth / 2.5)) ¬
scale image scale down proportionally
set {_buttons, butt_width} to create buttons {"Cancel", "Replace"} default button 2 cancel button 1
display enhanced window ¬
¬
¬
¬
¬
¬
"" acc view width AccViewWidth ¬
acc view height theTop - 50 ¬
acc view controls {Field_bottom, Field_top} & {labelText} initial position {} buttons _buttons
end makePrompt
use scripting additions
use script "Dialog Toolkit Plus"
set TheExampleTrack to "Paganini Etude No.4, in E Major (Vivo) - Paganini-Liszt"
set MaxLabelWidthValue to 600
set AccViewWidth to MaxLabelWidthValue
set Bottommost to 10
set spacer to 12
set labelText to "string"
set {_buttons, butt_width} to create buttons {"Cancel", "Replace"} default button 2 cancel button 1
set {Field_bottom, labelTex_at, theTop} to create side labeled field TheExampleTrack ¬
bottom Bottommost ¬
total width AccViewWidth ¬
label text labelText ¬
field left 200
display enhanced window "" acc view width AccViewWidth ¬
acc view height theTop + 30 ¬
acc view controls {Field_bottom} initial position {} buttons _buttons
Your script adds the labels. I can’t trace down the culprit of why my doesn’t. Changing the width, string length and field left values doesn’t make any diff.
When you create a labeled field DTK+ returns two acc view controls, the first for the field, the second for the label. Your display enhanced window command only used the one for the field.
use scripting additions
use script "Dialog Toolkit Plus"
set TheExampleTrack to "Paganini Etude No.4, in E Major (Vivo) - Paganini-Liszt"
set MaxLabelWidthValue to 600
set AccViewWidth to MaxLabelWidthValue
set Bottommost to 10
set spacer to 12
set labelText to "string"
set {_buttons, butt_width} to create buttons {"Cancel", "Replace"} default button 2 cancel button 1
set {Field_bottom, labelTex_at, theTop} to create side labeled field TheExampleTrack ¬
bottom Bottommost ¬
total width AccViewWidth ¬
label text labelText ¬
field left 200
display enhanced window ("") ¬
acc view width AccViewWidth ¬
acc view height theTop + 30 ¬
acc view controls {Field_bottom, labelTex_at} ¬
initial position {} ¬
buttons _buttons
Oh, thank you. Now, I see. However, this defies expectations as a top-labeled field implies the all-in-one reference, that is, the created UI element is field+label, not {field,label}, each of which is to be called separately. This is counterintuitive and is not illustrated in the example scripts and the DTK+ dictionary. Without listing the label explicitly, it’s just another instance of “create field”.
I see what you’re saying. Here’s a little background.
Field and Label are both ASObjC objects (accessory views). Since labels and fields (along with other labeled elements) are frequently used together Shane (the developer of Dialog Toolkit Plus) bundled them together in the same command, but they still have to be sent as separate objects.
Not intuitive, but easier than doing them separately (and having to do the math to get them correctly aligned). Once you get used to it, it becomes easier.
Also,
Here’s what the DialogToolkit + dictionary says the result is.
A list containing the field, the label, and the distance from the top of the label to the bottom of the accessory view.
I would prefer the results be more prominently displayed and maybe in their AE form, but this is what we have. Whenever I’m having an issue dealing with the result of a command (anywhere in applescript, not just libraries) I look at what the dictionary says the result is.