Getting text view values.

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.

Help! :slight_smile:

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_

Thank for the reply.

How do I access the log?

OK I set my own “log” lol

on subgo_(sender)
	display dialog "Button clicked"
	log "Button clicked"
	set valtext to valwintext's |string|()
	display dialog valtext
end subgo_

It gives me a dialog when I click, but the string bit is isn’t working.

The log registers it too.

Under the Run menu item in Xcode, choose Console. This is where all error and log messages will be displayed.

OK I saw some bad stuff in the log so I thought I’d show everyone.

What I did was launch using build and debug, type hello into the text view and click the button, then quit with cmd Q.

FYI, the only relevant parts to the output are:

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.

Oh that was only my way of testing the text view command.

Thanks, it works beautifully now.

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.