Creating a Startup Application Script in Ubuntu

If you are new to Ubuntu and have installed various softwares, eventually there comes a time when you want the applications to start automatically just after the system boots.
Following are two ways to add applications to startup list. First is Windows method, while the second method is geeky way (as you must have guessed, it’s my favourite).

Easy method

Just like Windows have a startup folder where you can place shortcut files and which would let you start the applications when user logs in, in Ubuntu there is a ~/.config/autostart folder where you can place the shortcut files. (Just to recall ~/ is your home folder. So ~/.config = /home/username/.config).
You can also use the Startup Applications tool (ships inbuilt with Ubuntu) which lets you add startup applications to that folder. Shortcut files in Ubuntu are files which ends with .desktop. The folder where you can find most of the .desktop files is /usr/share/applications. So you can just find the desktop file related to the particular application and copy the .desktop file into the ~/.config/autostart folder.
If you want to start the application for every user then you would need to copy the .desktop file in /etc/xdg/autostart folder.

Starup Applications Folder and Tool
Autostart Folder on the left and Startup Applications Tool on the right

Script Method

You can also create a .sh script file containing the commands to start the applications and then add this script in the “Startup Applications” tool. I prefer this method since I can easily modify the .sh script using a text editor and also easily make a backup of it, should I need to re-install Ubuntu in any case. This would also let me add the same script file to another copy of Ubuntu running on different PC.
To add a command to a script file you have to make sure that the command is correct. You can test the command by trying to execute it on Terminal. So for example if we want to start the browser Firefox in Startup we can first try to execute the firefox command from terminal, and make sure whether it really opens the Firefox browser.
Sometimes to start an application command wouldn’t be that straight-forward. Take an example of Transmission (Ubuntu’s torrent client). If you try to start the application using transmission command, you would receive a “command not found” error. To start Transmission following command is used:

transmission-gtk

To find the exact command that you need to put in the script file you can try to find the desktop file of the application and then find the line in it which begins with Exec. What follows is the command to start the application. So if you goto the directory /usr/share/applications/, navigate to Transmission and open this file in gedit, you can see that the Exec line is followed by transmission-gtk. That is your command to start the transmission application.

Exec line from .desktop file
Exec line from .desktop file

If you can’t find the .desktop file for a particular application you can search the .desktop file using the command locate. And then finding the lines beginning with Exec.

cat /usr/share/applications/transmission-gtk.desktop | grep Exec

Cat and Grep command to locate the Exec line
Cat and Grep command to locate the Exec line

Once you find the commands for all the applications you want to start when Ubuntu boots up you can list them in a single .sh file. To do this create a Text file and save it as StartUpApps.sh. Then open this file in gedit and write the commands in it with disown command. Below is my script file containing all the applications I want to start.

#!/bin/bash
#StartUpItems.sh : A list of all applications I need to startup when Ubuntu boots.
echo ">>>> Hello, Vyom. Starting up your programs... <<<<"
echo ""
echo ">>> Starting firefox..."
firefox -new-window & disown
echo ">>> Starting thunderbird..."
thunderbird & disown
echo ">>> Starting telegram..."
/home/vyom/Telegram/Telegram & disown
echo ">>> Starting steam..."
steam & disown
echo ">>> Starting transmission..."
transmission-gtk & disown
echo ">>> Starting dictionary..."
gnome-dictionary & disown
echo ">>> Starting uget..."
uget-gtk %u & disown
echo ">>> Starting Dropbox Daemon..."
dropbox start -i & disown
echo ""
echo ">>>> ALL PROGRAMS LOADED <<<<"

Lines starting with # are ignored by Terminal. Lines beginning with echo statements are not required, but I have included them to troubleshoot if execution of the script stops at some point. Every command is suffixed with & disown command, which releases Terminal and get it ready to execute the next command. Without the disown suffix script would halt at the execution of very first command where it doesn’t encounter disown. After this script file is prepared you can keep this file or it’s shortcut to the folder ~/.config/autostart. Now when you login to Ubuntu, this script file will get executed, and all the applications listed in them will be executed one by one.

Bonus:

You can use the Auto Move Windows Gnome extension to automatically move a particular application to a different workspace. This is useful if you don’t want to be disturbed by the front end of a program that should actually be running in background. Examples include Steam and Transmission application.

Auto Move Application extension allows moving applications automatically to a different workspace
Auto Move Application extension moves applications to a different workspace

References (for further reading):
http://askubuntu.com/questions/107187/how-to-launch-gui-app-with-upstart-script
http://stackoverflow.com/questions/5681010/stop-an-application-through-terminal
http://unix.stackexchange.com/questions/3886/difference-between-nohup-disown-and

One thought on “Creating a Startup Application Script in Ubuntu

Leave a Reply

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