3

I have a Mac application bundle which is executing a shell script. The shell script calls java program 1 to do some stuff and then launches the main java application. This process leaves one icon in the Dock for the shell script which shows the name from the application folder and one icon in the Dock for the java program.

Is there any way to prevent the shell script application icon from showing in the Dock?

3 Answers 3

6

Yes, assuming the first Java program can run headless:

java -Djava.awt.headless=true ...

Addendum: If you are using JavaApplicationStub, diagnostic output from the launch process may be obtained as follows:

$ export JAVA_LAUNCHER_VERBOSE
$ ./YourBundle.app/Contents/MacOS/JavaApplicationStub
3
  • I don't think it's the first java program's icon in the doc. I think that one goes away when the java program completes. It's like there is an icon for the shell script and one for the java program that is running. I want to get rid of the shell script icon.
    – GregA100k
    Jan 28, 2010 at 3:59
  • Puzzling. If the JVM does anything that would throw a HeadlessException, you'll see a dock icon for it. Is the second process a child of the first? Are you using JavaApplicationStub or just your script?
    – trashgod
    Jan 28, 2010 at 21:59
  • The JavaApplicationStub is not used. A shell script is what is getting executed. Each java program is being called separately by calling java...
    – GregA100k
    Feb 1, 2010 at 21:19
1

If you don't want the shell script icon in the dock, you need to start, at least the second java process for the main application, in exec mode:

exec java -jar XXX

exec means, it will "replace" your currently running shell with the new process. This seams exactly what you want.

My universalJavaApplicationStub for Java 6/7 is doing it the same way and it works just fine :)

0

Maybe you can run the Java program in the background and then exit the shell script? Something like this:

#!/bin/sh
first_java_program            # Synchronous, wait for it
nohup second_java_program &   # Run in the background, detach from terminal
exit 0                        # Indicate clean exit

Another option might be to run the shell script without Terminal.app but directly with the Unix-level system(3) call or something similar, with no GUI interaction.

1
  • This sounded like exactly what I needed, but the exit 0 line was not reached until after the second java program ended.
    – GregA100k
    Feb 1, 2010 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.