views:

621

answers:

2

Is it possible to add items to the applications dock menu?

EDIT: I think i miss phrased the question, i am not looking for a way to add an icon to the dock. what i am looking for is, when you right click on the itunes icon you get itunes control on the menu (play pause etc) i was wondering how can i add custom items to that menu.

+1  A: 

Yes (providing I understand the question).

If your just trying to customize the Java Icon in the Dock see ... http://developer.apple.com/documentation/Java/Conceptual/Java14Development/03-JavaDeployment/JavaDeployment.html#//apple_ref/doc/uid/TP40001885-208447-TPXREF120

Point two under OSX Application Bundles section "If you add an appropriate icon, it shows the application icon in the Dock, clearly identifying your application. (Otherwise, a default Java coffee cup icon appears in the Dock.)"

There is an example app (Java) for handling drag and drop events for your dock icon as well located here : http://www.devdaily.com/blog/post/jfc-swing/java-handle-drag-drop-events-mac-osx-dock-application-icon

If you want you application to automatically add it's icon during installation to the dock (possibly what you mean) you should know that there is no "official apple" way to do this as it's BAD design on OS X to force your icons into a users dock, and typically frowned upon. All MAC users i know will instantly remove your application as a result of such behavior.

That said however, you can review the system administration guides on Apple's site to see how it can be done programatically.

Robert French
+1  A: 

Look into the com.apple.eawt package. Specifically, when you initialize your app, do something like the following:

if (System.getProperty("os.name").startsWith("Mac OS X")) {
    // only do this setup if we know this is a Mac
    com.apple.eawt.Application macApp = com.apple.eawt.Application.getApplication();
    java.awt.PopupMenu menu = new java.awt.PopupMenu();
    // create your java.awt.MenuItem objects here
    // add to menu via java.awt.Menu#add(java.awt.MenuItem)
    macApp.setDockMenu(menu);
}

If you are distributing this as a cross-platform application, Apple provides an Apple Java Extensions jar with stubs for the com.apple.eawt package, so the code will compile with non-Apple JDKs.

wmorrell