Search code examples
linuxbashshellstartupgnome-terminal

Start Bash Script from Bash Script to Launch GUI Application


I am trying to launch a GUI application (rhythmbox) on a Ubuntu. In the following I try to explain the chain of executed files.

# Window manager executes first
~/i3wm_cmd_wrapper.sh Window_Name ~/mount_enc.sh

This wrapper uses gnome-terminal to execute stuff. This enables opening a terminal at startup where users can enter information.

# mount_enc.sh launches the following command in the end 
bash ~/launch_in_bg.sh rhythmbox

mount_enc.sh does exactly what it is supposed to do when starting from a normal terminal. But I'd like to start it automatically at startup and rhythmbox should be kept open after the script is done.

# launch_in_bg.sh is just doing what it's supposed to 
($PRGRM > /dev/null 2>&1) &

I can not get the gnome-terminal to open rhythmbox for me. Also I think my approach is wrong if I want rhythmbox to keep running after the gnome-terminal finishes executing the mount_enc.sh script. Can anybody think of a better solution?


Solution

  • If you open a program from the console (even in background), the process of the program is a child process of the console process and will terminate when the console process terminates. To keep the program's process running it has to be detached from the console process. Detaching can be done in multiple ways. Some examples:

    nohup rhythmbox &
    

    or

    rhythmbox & disown
    

    To suppress output, use redirection as in your script.