2

Is it possible to add another icon to the dock at runtime without using [NSWorkspace launchApplication:]?

How?


Before you say 'no': I am willing to use stuff like fork() etc.

I actually tried a bit with fork() but I get the error:

The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
Albert
  • 65,406
  • 61
  • 242
  • 386

2 Answers2

1

Launch another application, via e.g. [NSWorkspace launchApplication:].

Yuji
  • 34,103
  • 3
  • 70
  • 88
  • 1
    I cannot really use any access to the file system in my use case. – Albert Sep 11 '11 at 15:53
  • 2
    Why can't you? That's a bizarre and unrealistic restriction. – Jonathan Grynspan Sep 11 '11 at 16:04
  • @Jonathan: Well, that's the situation I have. – Albert Sep 11 '11 at 16:15
  • Not even to your own application bundle? – Flyingdiver Sep 11 '11 at 16:18
  • 1
    Sorry, Albert, but it's not a real situation on Mac OS X. Your process has file system access if it has access to anything else at all. – Jonathan Grynspan Sep 11 '11 at 16:49
  • @Jonathan: I have indeed some quite rare use case. I am injecting into another application and want to create another dock icon which is controlled by the same process as the other application. Of course I can do with some helper application but I would much prefer to do it more directly. – Albert Sep 11 '11 at 18:16
  • You can still use the file system in that situation. You're arbitrarily restricting what you can do. – Jonathan Grynspan Sep 11 '11 at 20:06
  • @Albert: unfortunately OS X's Dock only shows one or zero icon per process. You need to use a helper app to shown an icon. Or, you can inject the code **into the Dock** so that it shows an extra icon. (For example, while the app is being installed via App Store, I believe the download-progress icon is shown by the Dock.) – Yuji Sep 12 '11 at 03:20
  • For injecting into the dock itself, I probably also need a helper app with root privileges or so. There is still [my other question](http://stackoverflow.com/questions/7379419/fork-cocoa-process-and-re-init-cocoa-how), which, in case there is a positive answer there, would allow a hacky way also here to make another dock icon just with `fork()`. Anyway, for now, I accept your answer. – Albert Sep 12 '11 at 03:36
0

If you want to add an additional icon to the Dock, Yuji's answer is the easiest solution.
If you want to change the existing icon of your app, you can create a Dock tile Plug-In.
Those Plug-Ins were introduced with Snow Leopard and they allow you to display small informations even when your app is not running. (Like iCal's icon, which always shows the current date).

Apple's Dock tile Plug-In docs: http://developer.apple.com/library/mac/#documentation/Carbon/Conceptual/customizing_docktile/CreatingaDockTilePlug-in/CreatingaDockTilePlug-in.html#//apple_ref/doc/uid/TP30000986-CH4-SW1

Thomas Zoechling
  • 34,177
  • 3
  • 81
  • 112