My application uses NSStatusItem to be visible to the user.
So I set 'Application is agent (UIElement)' to YES, which basically hides the menu bar of the application, and hides the icon from the dock.
Now, I didn't delete the menu bar, so I can still react to shortcuts like cmd+W to close the preference window, or cmd+q to quit the application. The problem is, that anytime I use such a command, the menubar get's messed up.
I've noticed that other Apps which run in the background, like Growl 2, have the same issue.
I have no idea how to fix this.
Hopefully someone of you can help me
I'm running Mountain Lion.
thanks!
HINT
It probably has something to do with the 10.8 SKD. I have never noticed this issue before in any application.
How about move the whole Window menu to be Application menu submenu and then hide it?
You will still receive shortcuts and the highlited menu will be the application menu that is by anyway there (i suppose so, how else you will open preferences window? also shortcut?).
Related
I am developing a OS X app and want it to run without dock icon but with a icon in the menubar. I have added the menubar utility and tried to set the following code in applicationDidFinishLaunching:
[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
It works well, except that the app will still show the window when launched. How to prevent this? I can't set the LSUIElement in Info.plist because I want this behavior to be changeable in the runtime.
Thanks in advance!
Edit
It seems that the Visible At Launch is unchecked by default... I am using storyboard so I created a new project, choose Main.storyboard -> Window Controller Scene -> Window, and found it unchecked, but the window will still open automatically.
image (cannot post it directly with <10 reputation)
I have build a cocoa mac application which is a menubar app. When you click it, it opens a NSWindow.
The problem:
1. When I open the menubar app on Desktop1.
2. Then go to Desktop2 and open the app by clicking the menubar icon, the app opens, but the desktop moves back to Desktop1 !
It's a rather tricky thing.
I appreciate your help !
Thanks
Try setting your window collection behavior to NSWindowCollectionBehaviorCanJoinAllSpaces so that, well, it isn't restrained to a single desktop.
[newWindow setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces];
NSWindowCollectionBehaviorMoveToActiveSpace should also work, but is a little more finicky.
I want my app to have:
Menubar extra icon (by the clock)
App Menubar ("File, Edit, View, Etc")
I do not want my app to have:
Dock Icon
Is this possible? I am deploying for 10.6 and 10.7 via the Mac App Store if that matters.
Setting LSUIElement in the info.plist file removes the dock icon, but it also removes the menubar.
NSApplication's setActivationPolicy might be what you are after.
[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
Please note the discussion:
Currently, NSApplicationActivationPolicyNone and
NSApplicationActivationPolicyAccessory may be changed to
NSApplicationActivationPolicyRegular, but other modifications are not
supported.Needs links to running application
As per NSApplicationActivationPolicyAccessory's documentation you may need to programmatically ensure that the menu bar appears.
You could create two "separate" applications. One that has a dock icon and menu items,the other one has just the icon by the clock.
When you click on the icon by the clock it launches the dock application. When you close the dock application the 'background' application stays running.
If that model will work for you then that's the way to go. But I would weigh that effort against what File-Edit-View will do for you.
This is yet one more of those "how to switch from running with a dock icon to running without one" questions with a twist.. I don't want the dock icon but I do want a menu bar when the application is at the front. Is that possible?
Running an application with LSUIElement set to 1 in the plist will launch the application without a dock icon, not showing up in the command-tab switch list and without a menu.
You can switch from that mode to the "normal" mode with all three switched on via SetSystemModeUI from 10.2 onwards and via NSApplication setApplicationActivationPolicy since 10.6, but crucially there is no way back to the previous mode (go figure).
So one way around this would be to launch with LSUIElement = 1 and then activate the menu bar when the application gets the focus and deactivate it on the application losing the focus.. alas I can't find a way of doing that.
Can anybody help?
Best regards,
Frank
I too was looking for a solution, but it turned out to be quite simple:
In the project file Info.plist need to add the key
"Application is agent (UIElement)" = YES
Unfortunately, this is not possible. You can only transform the process type in one direction (from a background app to a foreground app) and not the other way.
I have a window that is set with NSBorderlessWindowMask, and also kCGDesktopWindowLevel. When a NSPanel is supposed to appear from say the selection of a Dock Icon menu or a Status Bar Item menu, the NSPanel will not display if the application is not the front most window.
So this program at this time only has a Status Menu Item (think how QuickSilver is implemented) and when I choose Preferences from my menu it is set to show the Preferences Panel by using Makekeyandorderfront, however unless you have just launched the application and done nothing else, when you select Preferences nothing happens.
I have found that when I choose my menu item for Sparkle's Check for Updates, that the check for update panel will appear and then my preference panel which I told to open will appear.
So it seems like makekeyandorderfront is not really bringing it to the front, perhaps.
Does anyone know how to fix this?
Should I call something besides makekeyandorderfront, or maybe something in conjunction with it?
Thanks in advance
Panels are designed by default to work this way. They're designed as auxiliary windows for your application and always disappear when the application deactivates. You will probably also run into issues with the panel becoming key... but to cure your disappearing panel issue, send this message to your panel:
[panelObject setHidesOnDeactivate:NO];
You should probably be using actual NSWindow objects here instead of NSPanel objects, but since I don't know much about how your application works, you'll have to look into that yourself. For more information on the difference between panels and windows, please review the documentation here: Window Programming Guide