Background application with menu bar - macos

I have an application which I would like to hide from the dock. Therefore Application is agent (UIElement) to YES.
Still, I would like to show a window to the user and therefore I would like to show a menu bar and have the window shown in the task switcher (CMD+Tab). Is there any way to do this?

Not as such, no. That's part of the meaning of UIElement. It can show windows, but not have a menu bar nor an icon in the Dock or application switcher (which is run by the Dock).
You can transform a UIElement to a normal application using -[NSApplication setActivationPolicy:] but not back again.
Your UIElement could launch a helper application to present the GUI, which would then quit when it's done. That might achieve the effect you're looking for, but will of course be more complicated.

I wouldn't do this. It's not the apple way and just gets confusing.
I guess NSMenuItem would be a good way to solve this.

Related

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];

Is there a way to make changes to the titlebar with GTK2?

I have a desktop application written in Ruby that is using GTK2. It's just a small test application to play with GTK2, but I'm having problems achieving what I want to do. Is there any way using GTK2 to get at the titlebar (apart from setting the title), specifically to either add a button to it (beside the min/max/etc, B in the below diagram) or to add an option to the menu that pops up when you click the icon on the titlebar (A in the below diagram)?
I'm thinking there might not be because GTK is meant to work with many many different window managers, but I just wondered if there was. As a side question, what event does clicking the 'cross' button fire? At the moment if the user clicks that the window disappears but the program doesn't end - I need to capture that event and quit the program.
Thanks for any help, including hitting me over the head and telling me how silly I am.
Note that this is possible in GTK 3.10 and up, by using gtk_window_set_titlebar(). It replaces the window manager's title bar with a custom one. GtkHeaderBar is a good custom title bar class to use.
You can't, however, make it look just like the window manager would, because you won't know which window manager the user is running.
No, the title bar is owned by the window manager and you will typically not have direct access to it.
When the user tries to close the window by clicking the window manager's button, the window will receive the delete event.

how do you display an NSMenu programmatically?

I wrote a little app that lives in the NSStatusBar. I want to have a global shortcut that when hit, the menu bar's content is displayed, exactly like the behavior of spotlight.
I have added a global key shortcut to my application, but I am unable to get the meun bar to display. How can I do this? I tried with "popUpContextMenu" , but that method displays the menu in the bottom left hand corner, I want the menu to open up right under the NSStatusBar menu icon.
You can do it, apple provides a method for it popUpStatusItemMenu:
I don't think there is a supported way to do this without perhaps using the Accessibility framework to simulate a click on your status item. Regardless, it's probably not a good idea to abuse a menu in this way.
The Spotlight menu bar item does not use an NSMenu, it uses a custom window/view. You might consider going this route if you have some sort of custom view to display.

Applescript access to last.fm app via application icon in menu bar

I want to create an Applescript to drive the last.fm player app. I'm trying to do this via last.fm application icon in the menu bar rather than using the main application menus, as this approach (I think) won't cause last.fm to switch to the foreground. The overall plan is to bind my script to a quicksilver trigger so I can stop|start|skip|love|ban|tag tracks from the keyboard.
My problem is I can't find what UI element to bind the applescript to. I've used UI Browser to scan through the UI object model but it draws a blank with the last.fm icon in the menu bar. Any thoughts appreciated.
Items in the menu bar are NSStatusItem and the part of the menu bar in which they live is an NSStatusBar. I suspect from past experience, though I am not sure, that if your applescript would have caused the main application to switch to the foreground, it will cause the menu bar item to switch to the foreground to the extent that it can, meaning that the application in the foreground will probably lose focus.

bring the application from in focus, by clicking the icon of corresponding application

I was surprised this doesn't happen automatically, but I would like my applications window to be in focus as I click its dock icon, when in minimized mode.
Just to clarify, when I minimize the app, the window goes to dock, but when I click the its corresponding Dock Icon, the window don't come in focus.
Is there anything I am missing?
I am using Qt 4.5.3 on Mac OS X 10.5, 10.6
Thanks for help.
Rahul
First answer: That's the expected behavior of a Mac app. Try Safari for example. An app can be active without showing any window. In that case, only the menu bar at the top shows that the active app is changed. So, unless absolutely necessary, you shouldn't bring the minimized window back unless the user explicitly does so. That's the Mac way!
Second answer: I understand that there are cases where you want to bring the minimized window up. In Cocoa, the application delegate method -applicationDidBicomeActive is called when the application gets the focus, and there you can bring the window up yourself. I'm sure Qt also has a similar event/callback/signal or whatever, but I don't know any Qt ... :p Sorry I can't be of any help.

Resources