-->

OSX two dock icons for same application

2019-08-30 05:49发布

问题:

I have two versions of the same application: version 1 located in /Applications(app1) and version 2 located in /Application Support(app2). In this context, I want that when launching app1, to redirect to app2, that means quitting app1, and launching app2.(I already implemented that using a command line tool, which will wait for app1 to finish, and launch app2).

This application has LSUIElement=1(status item mostly), however the application may appear in dock: if a window is opened from status item, I do:

TransformProcessType(&psn, kProcessTransformToForegroundApplication);

and when the window is closed, i do:

TransformProcessType(&psn, kProcessTransformToUIElementApplication);

Problem

Tthe problem that I am facing with is that if user selects Keep in dock for app1, and app1 redirects to app2, then the user will end up with two application icons in the dock.

I am searching for a way to overcome this behavior.

Questions:

  1. Does anyone tried to do this with exec* family? From the documentation I read that using this it should replace app1 image with app2 image, therefore it should help me in fixing my issue. I tried both execl and execle, and I did not manage to get the expected behavior. Note that when launching with execle, in XCode I get some assembly exception in dyld_start, app2 starts with success, but sometimes I had some errors in the logs(outlets or actions couldn't be located. not sure if these errors are related to execl).

  2. Is there any way of fixing this behavior, or tricking dock.app to think that these are the same application? I tried playing around with defaults for dock app, by modifying the "persisten-apps" array before starting app2, but it requires the restart of dock.app in order for the changes to take effect.

Any help will be highly appreciated.

Thanks

EDIT:

1. I created a test application with LSUIElement=0, and using execl everything works as expected. If I choose "Keep in dock" in app1, after opening app2 with execl, I end up with only one icon in dock.

2. If for the same application I set LSUIElement=1, and I display the dock icon(using TransformProcessType), after launching app2 with execl, I will end up with two dock icons. That means that on app1 I transform to foreground and select keep in dock. After I execute app2 with execl, if I transform the process to foreground, I end up with two icons in dock bar.

Does anybody have a solution for this behavior? Did anybody work with TransformProcessType and execl?