Wednesday, December 13, 2017

#1 2009-10-31 10:22:10 pm

ttt1107
Member
Registered: 2009-08-14
Posts: 63

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?


Filed under: window, reference, visible, outlet

Offline

 

#2 2009-11-01 01:55:07 am

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

Re: Reference a window in ASOC

ttt1107 wrote:

property mainwindow : missing value


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).

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


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


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

Offline

 

#3 2009-11-01 11:29:47 am

ttt1107
Member
Registered: 2009-08-14
Posts: 63

Re: Reference a window in ASOC

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.

Offline

 

#4 2009-11-01 11:58:07 am

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

Re: Reference a window in ASOC

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

Applescript:


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

Offline

 

#5 2009-11-01 12:40:00 pm

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

Re: Reference a window in ASOC

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

Offline

 

#6 2009-11-01 01:56:45 pm

ttt1107
Member
Registered: 2009-08-14
Posts: 63

Re: Reference a window in ASOC

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()
or
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?

Offline

 

#7 2009-11-01 02:28:56 pm

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

Re: Reference a window in ASOC

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|()

Applescript:

set thePass to secTF's stringValue()

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)