NSStatusItem menu does not show up in lion full screen app - cocoa

I have a foreground application that shows a NSStatusItem along with a menu (via NSStatusItem setMenu:(NSMenu *)menu). However, this menu does not display when I am looking at another app in fullscreen mode (say Safari) in Lion.
I know that I can make it work by setting NSBGOnly to true in the Info.plist file (or NSUIElement), but both methods will make my app icon disappear from the task switcher as well as hide the main menu once I manage to focus my app.
Finally, I have tried setting NSUIElement to true and do the following in my app upon startup (see also How to hide the Dock icon):
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
This made the menubar appear again as well as the dock icon but the original problem (status item menu does not show up in another fullscreen app) is visible again. Whatever I try, I can't win.
Any suggestions would be highly appreciated!

Unfortunately I think this is expected behaviour. Your app is considered a foreground app, so all its UI is disabled while another app is in full screen. You should file a bug if you feel that status items in foreground apps should still be available to other apps in full screen mode.
Probably the best solution would be to split your app into two parts, an agent app which has LSUIElement set to true, which creates and manages the status item and its menu, and your main foreground app which does most of the work and which launches and manages the agent app.
There are a variety of inter-process communication methods that you can use to get the two apps talking to each other, such as Distributed Objects or Apple Events.

Related

XCode: debugging mac app window is always on top across applications

I am developing an Mac OS app, and have preference window presented as model. This works just fine as I want and I don't want to change that behaviour. The problem is: when the window is shown, and I debug on some breakpoints, the preference window is still there, however, Xcode's app is in focused now, but the preference window from the current app still shows on top. This is annoying. I have to drag it to somewhere to see the Xcode window. Is there anything that I can do so that if the app is in debug mode, then that preference window should also be gone away with my app in background and just Xcode is in foreground?
When a window is run as a modal window, its window level is set to NSModalPanelWindowLevel, which is above normal windows. As a hack just for debugging, you could do something like this just before running the window as modal:
dispatch_async(dispatch_get_main_queue(), ^{
NSApp.modalWindow.level = NSNormalWindowLevel;
});
Another approach would be to just run your app on a separate desktop space from Xcode.

OS X run system application with GUI over all others including fullscreen apps

I'm trying to write an accessibility app based on a "no-click" mouse concept. The idea is to capture mouse gestures that will be interpreted as clicks and pass the events to other apps. I have most of it working, except that I don't know how I could run it on top of fullscreen apps post Lion. Right now the app window is transparent and follows the mouse around, but this approach won't work with other "Desktops" or full screen apps, as the app stays in its current desktop when switching.
Any ideas?
What I needed was to call
[self setCollectionBehavior: NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorFullScreenAuxiliary];
and also (important for the fullscreen apps!) set Application is agent (UIElement) to true in the info.plist file.

Always show Badge Count in OS X

Apple's own apps such as Reminders show Badge count even if they are not running or after quitting them
Other apps (some even with Helper apps) show badge when they are running, but it disappears as soon as you quit the application
is there a way, user side, or programming side, we can do to always show this badge, even when the app is not running?
I searched a lot in Google, didn't find anything about "always" showing this badge, maybe "badge count" is the wrong keyword
Yes, Create dock Tile Plug-in.
Starting in OS X v10.6, you can customize an application’s Dock tile
icon and menu when the application is not running.
When your application needs to customize the Dock tile, it manipulates the NSDockTile object that was provided to the initial call to the setDockTile: method.
To dynamically change the application's Dock icon, you can draw a Dock icon using a custom view. See Using a Custom View to Draw a Dock Icon.
To add text to a Dock icon, you can apply a badge label. See Changing the Text of a Badge Label.

Mac OS X - app without menu?

I'd like to build an app that does not have a menubar, a dock icon, or sits in the app switcher. Basically, it should be like Quicksilver: I'd active it through a global hot key, say from Safari, and a little window appears, but Safari does not get inactive, neither does a different menubar show. I hope you understand what I mean...
How would I do that? I can prevent the dock icon, the app switcher, but I do not know how I can prevent the other apps from becoming inactive when my app's window shows or how I can remove the menu.
Thanks for any hints!
Try searching for "LSUIElement". That should give you all the information you need.
(Specifically, this page in the documentation).
As Dave already said, add
LSUIElement YES
in your application's Info.plist file. That will get rid of icon and menu bar.
Then, to actually bring a window to the front at the appropriate time (e.g. when triggered through a global keyboard shortcut), you could do something like this:
ProcessSerialNumber psn = {0, kCurrentProcess};
SetFrontProcess(&psn);
[someWindow makeKeyAndOrderFront:nil];

How to create a helper application (LSUIElement) that also has a (removable) dock icon

I've submitted a helper application (using LSUIElement)to the Mac App Store. I was under the false impression that the App Store install process would put a dock icon for helper apps.
How can I create a dock icon that the user could remove, while the status bar app runs independently (like the popular app Caffeine)? Do I need to create a non-LSUIElement app that loads the LSUIElement app, or is there a better way?
Instead of using LSUIElement, use NSApplication's setActivationPolicy: method. By default, the application will have a dock icon, but by changing the activation policy to NSApplicationActivationPolicyAccessory, you get the same effect as LSUIElement while being able to change it programatically (the documentation for NSApplicationActivationPolicyAccessory says it is equivalent to LSUIElement=1).
- (void)applicationDidFinishLaunching:(NSApplication *)app {
if([[NSUserDefaults standardUserDefaults] boolForKey:#"HideDockIcon"])
[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
}
Apparently I was misinformed by my app reviewer (two of them actually). The dock icon is created for you by the install process. Pressing the issue, I was able to get the app through the review process.

Resources