when does on awake from nib execute for a window

I have: load nib “Window”, followed by some initialization, followed by show window.

Does show window trigger the on awake from nib Handler, or is it load nib, or both?

Some of my in-between initialization depends on at which point(s) awake from nib is triggered.

Thanks bunches.

Hello,

After a bit of testing, it seems that it is “load nib” that triggers the “awake from nib” event handler. Also, out of interest, if you use an “on will open” event handler for the window, the code in that handler is executed every time the window is opened, rather than only when the nib is loaded.

Quill

Thanks! For the first time I have created multiple xibs in my applescript studio app. One xib per window. However I was struggling to get the xib not mainmenu.xib to load. Previously because I’d create windows in mainmenu.xib they’d automatically load. Now because of this post I figured out how to get separate xibs to load. Load the new xib file by adding load nib “xib file name” into on will finish launching handler of script. For the new xib file’s owner select awake from nib, this triggers the window’s awake from nib. Phew! I prefer separate xibs for windows as in the past I’ve had interface builder files become corrupt. This way I’d only lose one window. :smiley:

Hmm, it worked once I wrote this post then tried again and it doesn’t work. Probably something corrupted. :frowning:

figured it out. I was getting an applescript error -2706 which is a stack overflow. I had put the load nib command in will finish launching handler. Once I moved the load nib command in on launched the nib loaded fine. Probably the main nib or some process hasn’t finished executing so it’s not ready to load another nib.

So disregard my previous statements. If you have multiple nibs/xibs. Have a on launched handler for file’s owner of mainmenu.nib. Example: on launched handler for window.xib

on launched theObject
load nib “window”
end launched

note no .xib at end of window. That should be it. Add extra load nibs for more xibs/nibs.