Something better than awake from nib?

Hi people!

I am currently using a mixture of Cocoa and AppleScript for my application. When I use the Cocoa “awake from nib” it loads my objects (the toolbar in this case) perfectly fast. The user doesn’t realize that it’s actually not an object dragged from the IB library. Though, I have several objects that rename itself using AppleScript depending on the preference they have chosen. These renamings also take place at launch, but during the AppleScript “awake from nib.” Sadly, with the AppleScript “awake from nib” you see how the objects change from the default to the option. That kind of doesn’t look to good … so what’s an alternative for that?

I tried “on will finish launching” but that one doesn’t work. :smiley:

Regards,

Max

I figured it out. You do use “on will finish launching theObject” but you have to make sure you set the Application object in IB3 to support AppleScript and then tick the option to “on will finish launching.” Otherwise nothing will happen.

There’s another way that I use to make sure my main window never opens before any of my object’s are instantiated and their values initialized.

a. Connect your application object in IB to the “launched” handler.
b. Also in IB uncheck the box “Visible at Launch” in the window attributes section of the inspector.
c. open the main window yourself in the “launched” handler of your code with: show window “windowName”

This means you control when the window opens and thus you can make sure to initialize everything in the “awake from nib” and “will finish launching” handlers before before you show your window in the “launched” handler.

There’s also another reason to do this. Applescript Studio has a quirk. If you have checked “Visible at Launch” then the order in which the handlers are called at application launch is as follows:

  1. “opened” handler for main window
  2. “will finish launching” for application
  3. “awake from nib” for app, window, then objects
  4. “launched” for application

Notice the #1 item there. If you use the “opened” handler for your main window then it actually gets called before any of the other handlers. This could mess you up if you try doing something in that handler before your objects are initialized in the other handlers. If you uncheck “Visible at launch” then the order becomes:

  1. “will finish launching” for application
  2. “awake from nib” for app, window, then objects
  3. “launched” for application
  4. “opened” handler for main window

This is the order you would expect. The first order is totally unexpected but that’s what happens when you use the “visible at launch” option. Since I sometimes use the “opened” handler, I just got into the habit of opening my main window myself then I never have a problem and I’m always certain my object’s are initialized before I show the main window.

Ah even better! I knew the command show window, but your idea never came to me. Thank you very much for this.

Thanks.

Max