script Dialog_MakerAppDelegate
property parent : class "NSObject"
property valwintext : missing value
property valwindef : missing value
on subgo_(sender)
set valtext to valwintext's |string|()
display dialog valtext
end subgo_
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return true
end applicationShouldTerminate_
end script
valwintext is paired with a text view, valwindef is paired with a text field and subgo_ is paired with a button. Entering text into the text view and clicking go doesn’t set off a dialog at all.
Check to make sure you have control-dragged from your object in IB to the NSTextView and not its scroll view. Also, add a log statement to your subgo_() handler ensuring it is getting called. Part 1 had a demonstration of making this connection.
on subgo_(sender)
log "Button clicked"
set valtext to valwintext's |string|()
display dialog valtext
end subgo_
2009-09-24 17:52:15.581 Dialog Maker[870:a0f] Button clicked
[Switching to process 870]
Dialog Maker(870,0x7fff7078fbe0) malloc: reference count underflow for 0x200650a80, break on auto_refcount_underflow_error to debug.
2009-09-24 17:52:15.615 Dialog Maker[870:a0f] *** -[Dialog_MakerAppDelegate subgo:]: Can't make «class ocid» id «data kptr00000000800A650002000000» into type string. (error -1700)
The text needs to be converted to a string
display dialog (valtext as string)
To convert your Dialog Maker script to an application, you will want to skip the use of display dialog. Use text fields, pupups, checkboxes, etc to gather the info.
Be prepared to do plenty of coercing. The stuff returned from ObjC calls all comes back in a special class (), and you usually can’t use them directly.