Search code examples
javamacosstatusbardockheadless

Mac status bar item but not on Dock


I'm trying to make a java application on Mac that puts an icon in the status bar, but I don't want the jar icon on the Mac dock (the one that has the coffee cup on the paper). So I tried to use the System.setProperty(java.awt.headless, true) technique, but then I can't put anything in the SystemTray menubar because I get an HeadlessException. If anybody knows a way to get around this, help would be appreciated.


Solution

  • it's easy... if you know how :)

    first wrap your jar file in a mac application bundle

    then go into the contents of your generated package and open the info.plist. there just add the LSUIElement property and set it to 1. this removes the application from the dock when started. also see the apple docs here: http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html


    for completeness: there's also another way to do this, but it's much more painful. there is a cocoa command that allows you to show/hide the dock icon dynamically: SetSystemUIMode (https://developer.apple.com/library/mac/#documentation/Carbon/reference/Dock_Manager/Reference/reference.html) you could either try to call this command using rococoa or write your own jni lib. alternatively i would have an xcode project which does something very similar -hide the menu bar- in my github account: https://github.com/kritzikratzi/jAppleMenuBar/ you'd only have to change some parameters in the src/native/jAppleMenuBar.m file.