Reference a window in ASOC

In applescript studio you could do:

tell the window “mainwindow”
set visible to true
end tell

But in applescript objective-c you can’t name them using the applescript tab because it is hidden. So how do you name the window so that this works or is there some other way you must do this. I also tried to set the window as an outlet but I just get this:

property mainwindow : missing value

Also how would you set the contents of a label in a window using code?

That’s the first thing; then go into Interface Builder, control-click on your script, then click and drag from the circle next to where it says “mainwindow” to the window itself, letting go when it highlights (making sure it’s the window and not its content view).

You use a property and link it as above, then use setStringValue_(“Some text”).

Yes that is what I did. In IB I made an outlet called “Mainwindow” then I right clicked (or control clicked) and draged the link from the little circle next the outlet “Mainwindow” and connected it to the window itself. After that I selected the controller and went to file and clicked write class files. Once back in xcode it showed:

property mainwindow : missing value

I did not write that myself that is what xcode wrote for me since I connected the outlet to the window.

Add a menu item or a button on another window and connect it to your handler.

on showWindow_(sender)
    mainwindow's makeKeyAndOrderFront_(sender)
end showWindow_

In IB, check the Window Attributes “Visible At Launch” for any window you want open when the application launches.

Ok I used your “mainwindow’s makeKeyAndOrderFront_(sender)” line and it works. At first it only worked for buttons but then I realized you have to change “sender” to “awakefromnib” for it to work in the “on awakefromnib”

Thanks for your help.

But now I have ran into another issue. I am trying to get the text a user typed into a secure text field and be able to set it to value such as:

set thepass to PassField’s title()
set thepass to PassField’s string()

But of course that does not work and I have tired other things in place of “string” but have had no luck. Any ideas?

NSSecureTextField is a subclass of NSTextField so it has all the methods of NSTextField.
NSTextField does not have a method called “string” and that is why it does not work.
You need to use “stringValue” instead.

NSTextView does however, have a method called “string,” but you need to call it with surrounding
pipes since “string” is an AppleScript reserved word.

→ set x to tf’s |string|()

set thePass to secTF's stringValue()