Bringing the blue cube to MainMenu.xib (in xCode 4.2)

Hello,

I have two objective C files that should make my main window floating.

I really don’t remenber anymore how I did this before in xCode 3.2, but I am sure I did it before.

I have to place these file in the project, and later make the blue cube for these two files show in MainMenu.xib.

Can someone tip me how?

Thanks!

This is the content of the two file I have added to my project:

// appDelegateAppDelegate.h
// appDelegate
//
// Created by Joby Abraham on 09/02/11.
// Copyright 2011 MyCompanyName. All rights reserved.
//

#import <Cocoa/Cocoa.h>

@interface appDelegateAppDelegate : NSObject
{
NSWindow *window;
}

@property (assign) IBOutlet NSWindow *window;

@end

// appDelegateAppDelegate.m
// appDelegate
//
// Created by Joby Abraham on 09/02/11.
// Copyright 2011 MyCompanyName. All rights reserved.
//

#import “appDelegateAppDelegate.h”

@implementation appDelegateAppDelegate

@synthesize window;

-(void) awakeFromNib
{
[[NSApplication sharedApplication] setDelegate:self];
}

  • (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
    NSLog(@“”);
    }

-(void) applicationDidResignActive:(NSNotification*) notification
{
[window setLevel:NSFloatingWindowLevel];
}

@end

The two scripts are delegate scripts. The blue cube should already be there. But if you want to insert them into an existing application:

If the app is written in Objective-C then paste the code into the existing application delegate .h and .m files.

If the app is written in AppleScriptObjC then you will need to convert the code into AppleScriptObjc if you want the code to run at launch.

In the app delegate:



property theWindow : missing value --the window you want to float

on applicationDidResignActive_(aNotification)
theWindow's setLevel_(current application's NSFloatingWindowLevel) --untested, but should work
end applicationDidResignActive_


You are going to run into the same problem you did in the “How to call a “Launched” event in ASOC???” post of having 2 app delegates, one in objective C and one in ASOC. If you are writing these apps in ASOC, you should get rid of these 2 objective C files, throw them out, banish them forever. There is no need to have these files, you can do what you want in ASOC.

What thewaytoapplescript posted will work with minor fixes – it needs “current application’s” in front of NSFloatingWindowLevel, and “window” should be “theWindow”.

property theWindow : missing value --the window you want to float

on applicationDidResignActive_(aNotification)
theWindow's setLevel_(current application's NSFloatingWindowLevel) 
end applicationDidResignActive_

I’m not sure if this is a good thing to do, however. Having your windows always in front, even if the user wants to open another app while yours is running is annoying and probably violates apple’s human interface guidelines. I think this should only be done for warnings or notifications, like an iCal event notification.

Ric

Thank you, rdelmar, for pointing out those errors. They are now corrected. :slight_smile:

Hi rdelmar,

Thanks guys.

It works for a new project!

Note:

It doesn’t work for another project that had many lines of code…

I guess this new enviroment is painfull…

Take care, you are all most kind…

There’s no reason it shouldn’t work as long as the script the method is in is the app delegate, and you have the IBOutlets for the windows properly hooked up.

Ric