Working with NSTextView in NSScrollView

This is my first post. I apologize ahead of time because I’m sure this is a huge NOOB question; however, I have spent several days searching and trying different code without success. So here goes.

I have a simple script and it basically takes text and displays it in a NSTextField; however, I’d like to transition this NSTextField to a field that scrolls. My understanding is that the most common way to do this is to use the NSTextView in NSScrollView. Up to this point I’ve been successful in exchanging data between two simple NSTextField’s using:

set my textField to "The Text To Display"

However, once I drop in a “NSTextView in NSScrollView”, with the same name and connections, I’m unable to send/receive data from the NSTextView.

I understand that setting these up is slightly more complicated and I’m struggling to find an applescriptobjc resource that clearly explains each step involved. I also understand that placing data on the NSTextView is a slightly different process. I’ve tried several iterations of the following without success:

textField's setString_("TEST")

I’m guessing that this is more of an issue related to setting up the correct connections with the “NSTextView in NSScrollView” because my defined variables are not showing up upon initial loading of the project. In that past they have always loaded correctly into the simpler NSTextField:

property textField : missing value

Any guidance you can provide would be greatly appreciated. Thank you again.



first of all make sure that the property textField is connected to the NSTextView not the NSScrollView.

NSTextView uses a subclass of NSText to manage the appearance of the text unlike NSTextField which uses a simple NSControl instance.

The normal way to put text into a NSTextView is

textView's textStorage()'s setAttributedString_(attributedString)

textView is the NSTextView instance and attributedString an NSAttributedString instance

You get an attributed string with

set attributedString to current application's NSAttributedString's alloc()'s initWithString_(aString)

aString is a normal NSString or AppleScript string

Hello StefanK,

Thank you for the clear and prompt response. I believe I now have the embedded NSTextView with the correct connections; however, I’m not entirely clear on how to handle the set text code below:

textView's textStorage()'s setAttributedString_(attributedString)

If my NSScrollView embedded text is called “TextView1”, my scroll view is called “MainScrollView”, and my text is simply “Test”. I believe that would change your example to the following:

TextView1's textStorage()'s setAttributedString_("Test")

How do I hand the following component?


Sorry again for the trouble. Your help is greatly appreciated!


set attributedString to current application's NSAttributedString's alloc()'s initWithString_("Test")
TextView1's textStorage()'s setAttributedString_(attributedString)