Friday, December 15, 2017

#1 2009-09-24 11:09:25 am

Richard
Member
From:: Herefordshire, UK
Registered: 2009-09-09
Posts: 529
Website

Getting text view values.

Applescript:

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! smile

Offline

 

#2 2009-09-24 11:34:39 am

Craig Williams
Administrator
From:: Ft. Smith, AR
Registered: 2006-12-07
Posts: 888

Re: Getting text view values.

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.

Applescript:

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

Offline

 

#3 2009-09-24 11:38:16 am

Richard
Member
From:: Herefordshire, UK
Registered: 2009-09-09
Posts: 529
Website

Re: Getting text view values.

Thank for the reply.

How do I access the log?

OK I set my own "log" lol

Applescript:

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.

Last edited by Richard (2009-09-24 11:43:18 am)

Offline

 

#4 2009-09-24 11:41:10 am

Craig Williams
Administrator
From:: Ft. Smith, AR
Registered: 2006-12-07
Posts: 888

Re: Getting text view values.

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

Offline

 

#5 2009-09-24 11:53:27 am

Richard
Member
From:: Herefordshire, UK
Registered: 2009-09-09
Posts: 529
Website

Re: Getting text view values.

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.

[Session started at 2009-09-24 17:52:03 +0100.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1344) (Fri Jul  3 01:19:56 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys000
Loading program into debugger…
sharedlibrary apply-load-rules all
Program loaded.
run
[Switching to process 870]
Running…
[Switching to process 870]
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)

Debugger stopped.
Program exited with status value:0.

Last edited by Richard (2009-09-24 11:54:46 am)

Offline

 

#6 2009-09-24 12:00:50 pm

Craig Williams
Administrator
From:: Ft. Smith, AR
Registered: 2006-12-07
Posts: 888

Re: Getting text view values.

FYI, the only relevant parts to the output are:

Applescript:

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

Applescript:

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.

Offline

 

#7 2009-09-24 12:10:34 pm

Richard
Member
From:: Herefordshire, UK
Registered: 2009-09-09
Posts: 529
Website

Re: Getting text view values.

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

Thanks, it works beautifully now.

Last edited by Richard (2009-09-24 12:15:15 pm)

Offline

 

#8 2009-09-24 07:37:37 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

Re: Getting text view values.

Be prepared to do plenty of coercing. The stuff returned from ObjC calls all comes back in a special class (<ocid>), and you usually can't use them directly.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)