On 30 Aug 2015, at 1:20 am,
email@hidden wrote:
I'm using Shane Stanley's "Dialog Toolkit" and as an experiment wanted to set up cocoa bindings between a text field and a label. I would like to setup continuous updates from the text field so it would show any keystroke changes but am having some difficulty using the right terminology for it.
I didn't like your chances of getting this to work, to be honest, but it looks like it does. The options parameter requires a dictionary, so you could add something like this:
set theOptions
to
current application's
NSDictionary's
dictionaryWithObject
:
true
forKey
:(
current application's
NSContinuouslyUpdatesValueBindingOption
)
And your bind parameter is also problematic -- you need
current application's NSValueBinding. Throw in a placeholder for when the label is empty and your script becomes:
use
AppleScript
version "2.3.1"
use
scripting additions
use
framework "Foundation"
use
framework "AppKit"
property textFieldOutlet
:
missing value
property
labelOutlet
:
missing value
property
boundProperty : "Initial state"
tell
script "Dialog Toolkit"
check for main
-- make sure we are in foreground when testing
set
theLabelStrings
to {"Random Text", "Random Text", "Even more randome text"}
set maxLabelWidth
to
max width for labels
theLabelStrings
set controlLeft
to maxLabelWidth
+ 6
set {
labelOutlet,
theTop,
newWidth}
to
create label " total per queue."
left inset 0
bottom (0 + 8)
max width 250
aligns "left"
without
multiline
end
tell
set theOptions
to
current application's
NSDictionary's
dictionaryWithObjects
:{
true
, "No entry"}
forKeys
:{
current application's
NSContinuouslyUpdatesValueBindingOption
,
current application's
NSNullPlaceholderBindingOption
}
labelOutlet's
bind
:(
current application's
NSValueBinding
)
toObject
:me
withKeyPath
:"boundProperty"
options
:theOptions
tell
script "Dialog Toolkit"
set {
textFieldOutlet
,
textFieldLabel
,
theTop
,
fieldLeft
} to
create side labeled field
"the field" placeholder text
"Stop ID" left inset
0 bottom
(
theTop
+ 8) total width
250 label text
"textFieldOutlet" field left
controlLeft
end
tell
textFieldOutlet's
bind
:(
current application's
NSValueBinding
)
toObject
:me
withKeyPath
:"boundProperty"
options
:theOptions
tell
script "Dialog Toolkit"
set allControls
to {labelOutlet
, textFieldLabel
, textFieldOutlet
}
-- controlResults will in the same order as allControls
set {
buttonName
,
suppressedState
,
controlResults
} to
display enhanced alert
"The main title." message
"some other stuff" as
informational
buttons
{"Cancel", "OK"} giving up after
120 acc view width
250 acc view height
theTop
acc view controls
allControls
without suppression
log
controlResults
set {statusMessage
, textFieldLabel
, textFieldOutlet
} to controlResults
end
tell
Nice...