views:

35

answers:

2

I want my application to become the top-level window on the OSX desktop when it needs to display important information. How would you go about doing this in cocoa?

+2  A: 

You mean you want to hijack the user's screen? Can you not just call requestUserAttention: on NSApplication? If you really must hijack the screen then look into setLevel: in NSWindow. Just keep in mind that any user like myself is going to delete your application as soon as you hijack the screen unless there is a very good reason to do so. Whenever you are thinking about doing things like this look at http://developer.apple.com/mac/library/documentation/UserExperience/Conceptual/AppleHIGuidelines/XHIGIntro/XHIGIntro.html first, then decide if it is the right course of action.

theMikeSwan
The reason is because the application is part of a suite that requires one application to hand off control to another application that is currently running which will show a dialog and handle other activities so it is not just a mere matter of getting the user's attention. Perhaps you know of a better way to handle this? Sorry I didn't describe the desired functionality better.
stinkbutt
If you are looking to have app A pass info to app B and have all of app B move forward take a look at `NSWorkspace` perhaps one of its methods such as `launchApplicationAtURL: options: configuration: error:` could help you out (I haven't used them myself, but even if the app is running it ay move forward). If you just need to have the window of an app move forward check out the method `setLevel:` in `NSWindow` `NSScreenSaverWindowLevel` should be higher than any other window on screen (I've never tried it but I would start there).
theMikeSwan
It looks like Apple won't allow anyone to pop up a window unless you are the active application because it's not "good practice" or apparently a security problem. I searched a lot of other threads attempting to do this but it looks like my users will just have to pay attention to the bouncing icons or suffer.
stinkbutt
I guess they changed that at some point, I know once upon a time you could set a window so that it was above all other windows no matter what. People used to like to put startup windows on that level, and was irritating to launch an app and be forced to wait until the startup screen went away.I take it `NSWorkspace` was of no use either?
theMikeSwan
NSWorkspace doesn't really allow you to manipulate several applications however, I think I can use launchApplication and it will bring the app in question that is supposed to handle the user input to the foreground. Although it's a bit of a hack, it got the job done. Thanks.
stinkbutt
+1  A: 

I want my application to become the top-level window …

You can't, because an application is not a window.

… it needs to display important information. How would you go about doing this in cocoa?

Send the NSApplication object a requestUserAttention: message. The user will activate your application in their own time (e.g., after they finish typing their password in somewhere).

Peter Hosey