Text Views And Radio Matrixes

how do i set/get the contents of a text view? this doesn’t work

set contents of text view "HeaderFile" to header of activetheme

and how do i find out/set which radio button is selected in a matrix?

there’s no useful documentation on this, and the as dictionary is SO not helpful.
please help me!

Try:

set contents of text view "HeaderFile" of window "WindowName" to header of activetheme

Unless that line is inside a [tell window “WindowName”] block. If still not working, is the text view part of a scroll view? Is it inside a box?

To get/set a row in a matrix I use:

set current row of matrix "MatrixName" of window "WindowName" to 1
get current row of matrix "MatrixName" of window "WindowName"
get name of current cell of matrix "MatrixName" of window "WindowName"
set enabled of cell "CellName" of matrix "MatrixName" of window "WindowName" to false

Took me quite a while to figure out when to use which… Hope it helps!

thanks. yes, the text view script i tried was inside a tell window block. is it inside a box? i dont know, i just dragged a text veiw into my interface, gave it an applescript name, and now i’m trying to use it, which doesn’t seem to be to simple :frowning:

Eeeeeeem… ups! If you check IB, the info window for any object will show it’s properties, that you obviously know. When you select your text view and attibutes (apple + 1) in the info window you get the settings for the text view, but if you hit (apple + 7 (8 in Tiger, so I read…)) you get the applescript settings for the “NSScrollView”… notice the title change of the info window. You should address your text view as follows:

set contents of text view of scroll view "HeaderFile" to header of activetheme -- this worked for me, exactly as is (with something else after the 'to' of course).

By “in a box” I meant that you can place text fields or views inside boxes (check Cocoa-Containers in IB’s window for inserting things). Then the above script line would turn:

set contents of text view of scroll view "HeaderFile" of box "BoxName" to header of activetheme

And no thanks needed, you’ve helped me before, so we’ll call it even! :wink: Now for a challenge!! Discover how to set fonts for the text placed in the text view. Set some word bold, italic, change it’s size, whatever… I managed to get words:

set FirstWord to get word 1 of text of text view 1 of scroll view "ScrollViewName" of window "WindowName"
-- set FirstWord to get font of word 1 of text of text view 1 of scroll view "helptext" of window "help" -- crashes!

But no idea how to set their fonts or anything else, altough ‘font’ is a reserved word. Anyway, if your interested… I’d be thankful!

first of all, thanks again, it worked!
as for the title in the applescript pane (yes it’s command + 8) it’s the same. is this different in panther?
I think someone has to write a list of cocoa interface objects, their applescript names and main settings. i’ll look into setting fonts (and sizes, which also interests me).

Yes, it seems to be different in Panther (XCode 1.1; Interfece Builder 2.4.1), the info window changes it’s title from NSTextView to NSScrollView when changing from the attributes to the applescript pane. Don’t know… I’ll find out when I get my hands on Tiger!

Now with the fonts issue, I found some things searching Google, I guess the most convincing was this one by jj, who is known to be around this forums also, maybe he could give us a hand. The news is that his suggestions didn’t work completely, or I didn’t get it (bad news in either case, at least for me… :stuck_out_tongue: ). I mean, the setting a font thing didn’t work. The size and color worked ok, but the “Verdana” (or any other font name) part return a warning in the event log window while running the application. To be known:

Strangely enough the AppleScriptKit.asdictionary says that ‘font’ is a property of class ‘word’ in the Text Suite. Then again… so is it of the class ‘text view’ in the Text View Suite but neither option worked… never quite understood the dictionaries… :confused:
I’m assuming that this is the Dictionary I should be checking when writting Studio Apps…?

Saludos! Adios!

Hi Nikel,

Here’s an excerpt from studioreference.pdf:

font
Plural: fonts
Inherits from: None.
Cocoa Class: NSFont
Not supported (through AppleScript Studio version 1.2). However, see the
Examples section for information on setting fonts in Interface Builder.
Examples
You can set the font family, typeface, size, and color for text field (page 314), text
view (page 520), and related classes in Interface Builder with the Font panel, shown
in Figure 3-2.

I’m running Jaguar. You might test if font is implemented by building a simple app. I made a simple text view and connected the following script to the text view:

on awake from nib theObject
tell theObject
set content to “hello”
end tell
set t to a reference to (text of theObject)
set f to font of t
end awake from nib

I get error something like:

NSCannotCreateScriptCommandError (10)

I don’t know if it is implemented yet post Jaguar, but you can try something like this. Note that I connected the script to the text view, so theObject is the text view and not the scroll view.

gl,

hi,
i’m having dome trouble with the matrixes, tried your code, not working. any ideas?

Kel, the font thing doesn’t work in Panther either. I’ve tried any combination I could think of and it just doesn’t work. Only size and color worked ok :frowning: I guess I’ll give up. Anyway, I wont die in frustration if I can’t get some text to have a font!

Lobster… I don’t know what you’re talking about, sorry… Dome problems? I guess my english only got that far. What exactly isn’t working? The code I posted worked for me, if you meant that one.

I’m trying to make a script that will 1. check what button is selected in a NSMatrix 2. set the selected button to something else. your scripts didn’t work, do you have any idea what i’m missing?

I have no idea! My code worked for me…! Can you post some context? Did you just put a matrix inside the window? If that was it then it should work. I’m using the same code in my Studio App and it works just fine! Maybe it changed in Tiger…

set RadioOut to title of key cell of matrix "RadioButtons" of window "aWindow" --gets the text next to the radio button of the selected button

tell matrix "RadioButtons" of window "aWindow"
			set title of cell 1 to "I am a button. Click me."
			set enabled of cell 1 to true --fiddle with this
			set transparent of cell 1 to false --fiddle with this too
end tell 

thanks anaxamander, i was able to set the title, but mainly what i need to do is get the title (title of current row doesn’t work) and change what row is selected
nikel, here’s the code

tell tab view item "ThemesTab" of tab view "TabThing" of window "MainWindow"
	tell matrix "PhotoResize"
		set title of cell 1 to "I am a button. Click me." --works!
		display dialog title of current cell -- error
	end tell
end tell

set RadioOut to title of key cell of matrix "PhotoResize" of tab view item "ThemesTab" of tab view "TabThing" of window "MainWindow"

–what is it with radio matrixes and tab views? I have the same setup. It must be a natural pairing or something.

thanks, also this isn’t working (it works on a apple sample…) any ideas why?

set current row of matrix "PhotoResize" to 2
		set selectedRow to current row of matrix "PhotoResize"
		display dialog selectedRow

no errors, just no. 1 stays selected and it displays an empty dialog

It works fine for me - I made a stripped down application with just those interface elements named as yours with a single button:

property choosen : boolean

on clicked theObject
	if (choosen is not true) and (choosen is not false) then
		set choosen to true
	end if
	if choosen then
		set current row of matrix "PhotoResize" of tab view item "ThemesTab" of tab view "TabThing" of window "MainWindow" to 2
		set choosen to false
	else
		display dialog "Can I help You with Something?"
		
		set current row of matrix "PhotoResize" of tab view item "ThemesTab" of tab view "TabThing" of window "MainWindow" to 1
	end if
	set selectedRow to current row of matrix "PhotoResize" of tab view item "ThemesTab" of tab view "TabThing" of window "MainWindow"
	display dialog selectedRow
end clicked

LobsterMan wrote:

It has happened to me that a [display dialog title of …] didn’t work. In those cases I usually fixed it splitting the dialog in two parts:

tell tab view item "ThemesTab" of tab view "TabThing" of window "MainWindow"
   tell matrix "PhotoResize"
       set title of cell 1 to "I am a button. Click me." --works!
       set CurrentRow to title of current cell
       display dialog CurrentRow -- now? Still error?
   end tell
end tell

On your last post, you say ‘selectedRow’ simply displays an empty dialog? I’ll asume it’s inside all the necesary [tell] blocks… Take a look at this post, it says something about tab views. This other post also talks about it, but I’m not so sure it’ll help much.
There seems to exist a ‘text view’ as a part of the ‘tab view item’, maybe the matrix is inside it? I don’t know… I never used a tab view before.

I also found this here:

set contents of text field "status2" of view of tab view item "actions" of tab view "maintabs" of window "main" to ts

I hope some of it helps. Let us know!

all working now, my bad. i set the matrix to 1 row, 2 columns, i should’ve used “current column” not “current row” working now!!! :smiley: