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.
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)
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?).
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.
I have a menulet app with an NSTextView in it. I don't want the app to appear in the dock, so I wrote
<key>LSUIElement</key>
<true/>
in the Info.plist file.
But if this option is enabled, somehow an NSTextView in the menu stops responding at all.
How can I make it respond again? Maybe there are any other ways to hide the dock icon?
Thank you!
IMPORTANT UPDATE: This bug has been spotted only on Mac OS 10.6 and higher
The documentation states that keyboard events are not supported in views that are attached to a menu item (see Application Menu and Pop-up List Programming Topics).
That said, I had no problem creating a minimal sample app without Dock icon and a text view embedded in a status item's menu, so your problem is likely somewhere else. You can download my sample app here.
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.