-->

How to remove the dock icon of a shell executable?

2019-07-04 01:06发布

问题:

I have a java application built with Eclipse, for Mac OS X. This app is installed via a .pkg file and supposed to be daemonized. Everything works fine, with Macbooks (Pro, Retina), but with the iMac I work on, when the application launches, i have an icon on the Dock, as you can see on the following link.

I have already tried the solution in this topic: stackoverflow.com/a/620950/3641679 but it didn't work (I still have the Dock icon). Currently the Info.plist looks like this.

What can I do?

Thank you for the time you'll be taking to help me.

Informations (assuming the app name is testapp)

  • I stop or start the daemon using launchctl start/stop
  • When I double click on the executable (in testapp.app/Contents/MacOs/testapp) i have the testapp.app in the Dock (with the icon file specified in the Info.plist). Here is a screenshot res.cloudinary.com/doit0eqlo/image/upload/v1400750376/app_k3adzh.png
  • Sorry for some links, I must have 10 reputation to post more than 2 links.

回答1:

Add this to your info.plist: -

<key>LSUIElement</key>
<true/>

Note that the value here is set to 'true' and not 1

As the Apple docs state: -

Specifies whether the app is an agent app, that is, an app that should not appear in the Dock or Force Quit window. See “LSUIElement” for details.



回答2:

So, I finally found the solution! The solution is in several steps.

Step 1: Editing the Info.plist

I had to add the LSBackgroundOnly key. It is a string and has to be set to 1.

As said in the Apple Documentation :

LSBackgroundOnly

specifies whether this app runs only in the background. If this key exists and is set to “1”, Launch Services runs the app in the background only.

Information:

Although the documentation specifies this key is a boolean, setting it to a string with the value 1 in it does the trick.

To do so:

  1. Go to your app's folder

  2. Go into the .app's folder then the Contents one (eg. /Applications/test.app/Contents)

  3. Open the Info.plist with any text editor you want (SublimeText, TextEdit,Xcode, etc.)

  4. Add the following lines before the closing dict tag (</dict>)

<key>LSBackgroundOnly</key>

<string>1</string>

Save everything.

Step 2: Edit the appname.ini

Initially I only did the part 1, so it wasn't enough. I found the solution in this question.

The file is in the 'Contents/MacOs' folder inside your application's .app (e.g /Applications/testapp.app/Contents/MacOs/testapp.ini).

  1. Open the .ini file (with any text editor you want).

  2. Before the -vmargs line, add the following line: -nosplash

  3. After the -vmargs line, add the following two lines:

    -Xdock:hidden
    -Dapple.awt.UIElement=false

Save the file, and now you can launch the app: it shouldn't be any icon neither in the Dock nor in the 'Force Quit' window, but your app should be running in the background.

Hope this helps,