Create a launcher script for Linux desktop

Using i3wm, I’m very pleased with the fact that at startup I can found all my everyday applications opened and placed on the relative workspaces. Anyway, sometimes I need different configuration (especially on the netbook) and I fit better with a manual launch of the programs.

Bash, bin and nohup to make an easy starter script

With nohup we can launch programs from terminal and leaving them active in background. In a terminal window, prefixing a command with nohup prevents it to be aborted with a log out or exiting the shell. So, we can use it to make a script that launches many applications and leaves them opened.


#! /bin/sh
#
# A starter launcher - cialu©2017
#
#

echo "..."
echo "...starter launcher is working"
echo "..."

nohup nm-applet &
nohup thunderbird & disown &
nohup /opt/Telegram/Telegram & disown &
nohup firefox & disown & exit 0

The disown builtin command is used to remove jobs from the job table, or to mark jobs so that a SIGHUP signal is not sent to them if the parent shell receives it. The exit command terminates a script, just as in a C program. After the script terminates, the command-line gives the exit status of the script, which is, by convention, 0 on success or an integer in the range 1 – 255 on error. So, we put an exit 0 command as the last command.

Edit the script and save it in a correct location, for example, with:


$ sudo vi /usr/local/bin/starter.sh

Make it executable:


$ sudo chmod +x /usr/local/bin/starter.sh

Logout or reboot to make it effectively working. And, finally, launch it:


MOD + D

starter + <CR>

You can also use it on other Linux desktop environment, but you could be forced to create a .desktop file like explained here.

 

How to avoid the ‘nohup.out’ output file in home folder

If nohup command has something to communicate or/and results some errors, you’ll find a ‘nohup.out’ file in your home directory. It’s annoying, because you need to remove it manually every time.

The solution (in Bash) is to redirect the nohup command output to /dev/null or to another location if you need to check and control the file. So, you can do something like that explained here in Redirect both standard error and standard out messages to a log file or to /dev/null.


#! /bin/sh
#
# A starter launcher - cialu©2017
#
#

echo "..."
echo "...starter launcher is working"
echo "..."

nohup thunderbird > /dev/null &
nohup hexchat > /dev/null &
nohup /opt/Telegram/Telegram > /dev/null &
nohup firefox > /dev/null & exit 0

Leave a Reply

Your email address will not be published. Required fields are marked *