NSTextView for logging... not even close!


I’m just starting out in AppleScript. I’m writing what will become a universal app that I can deploy to a bunch of machines of varied vintage.

My problem du jour centers around an Interface that has some very plain elements: text fields, popup buttons, and a text view to spit out informational messages. I considered the text view as an alternative to dialogs and alerts because it can be as informative and simultaneously unobtrusive as I need it to be.

The offending routine is as follows:

on appendLogging(catText)
	set mainText to "sample text"
	set theObject to "MainWindow"
	tell text view 1 of scroll view 1 of theObject
		set mainText to contents & return
		set contents to mainText & catText
	end tell
end appendLogging

The phenomena:
a) using “text view “textPanel”” et al produces error “Can’t make “textPanel” into type integer. (-1700)”
b) using “text view 1” et al produces error “Can’t get <> 1 of MainWindow”. (-1728)"
c) using “content” versus “contents” seems to make no difference
d) these occurrences are too early in the routine to try a “log” statement.

I don’t know enough about the underlying programming doodads to make any valuable deductions from the error messages in a) and b). Can anyone help me to understand what’s going on?

Edit: Sorry, I can’t read. :rolleyes:

The line…

set theObject to "MainWindow"

…should probably read…

set theObject to window "MainWindow"

I strongly recommend avoiding the use of numbered references to objects. Provide an applescript name for every object you intend to reference programmatically, as you appear to have done with your window, and reference them using their unique name. Also, using ‘content’ instead of ‘contents’ can (but doesn’t always) make a difference, so I would recommend sticking to using ‘content’ unless you have a good reason not to. It’s just a good habit to get into, in my opinion.

Something along these lines is what I might use…

to appendLogging(catText)
	tell text view "myTextView" of scroll view "myScrollView" of window "MainWindow"
		if (content is not "") then --> Only add a return if there's already something there
			set content to (content & return & catText)
			set content to catText
		end if
	end tell
end appendLogging


I would recommend reading the documentation for the class and determining what you should use, rather than make an assumption.

This part specifically, as it relates to the content and contents of a text view:

See also: Text View Suite

Thanks for that mikey-san, that helps a lot. Didn’t you learn a lot from that thoughtful and provocative contribution the wise and powerful mikey made, torch? :rolleyes:

My post: knowledge acquired from experience actually observing patterns in what people need and offering them actual code, examples, and one-on-one private help with applescript studio projects for many years. Mikey’s post: unnecessary and negative, continuing with your habit of stating only your narrow opinion and failing to back up your statements with any even remotely concrete or helpful input for the original poster. You posted no sample code, no suggestions (other than to ‘go figure it out yourself’), and took only the time it required to find one thing wrong (again) with something I said and to publicly make a spectacle out of it.

While you may not actually care whether other users come away with lasting, relevant insights when you post something… I do… and I’ve helped enough people in this forum to recognize that giving the advice to not use the contents property unless necessary can save a lot of people a lot of frustration. If you can’t say something constructive, mikey, why bother saying anything at all? I think that it’s just to stir up conflict, as your tone and demeanor show nothing but contempt and disrespect for the time that I personally donate to this forum. If you’ve got to spray your attitude, at least try harder to do more than simply point out potential flaws in others’ work. I spent a good fifteen minutes working up a demo project, testing my code, and took the time to not only make my suggestions but to take a minute giving extra insight into the problem and the solution. You spent thirty seconds being a jerk. If all you’re here to do is float your own boat, well, that’s a shame.

Take care all, even you mikey. Oh, and Bruce… thanks for writing the post that mikey’s kind and generous side (if he has one) probably should have written in the first place.


here, here.

Keep up the good work on this list.

All the best