Create a Launcher in Ubuntu Using Bash

by
Share this Article: Facebook24Google+10Twitter14LinkedIn0Reddit0StumbleUpon0
"Hi Oltjano! How are you? Can you help me to create an executable file in Ubuntu? I want it to start my lamp server, I want to save time and I don't like to type long commands in my terminal."

This was a message from my friend that is learning web development in his Ubuntu laptop. Time is priceless and finding a new easy way to get the job done is one of my priorities. I have some experience with Bash scripting so I decided to help my friend with a simple Bash script that starts up his LAMP server. The script is very easy to write and understand even for a newbie, but the idea is to tell you how important and powerful is shell scripting, in our case Bash.

You can do magic with a few lines of code and automate repetitive tasks that take your irreplaceable time everyday. My friend  knew how to start the LAMP server from terminal with the ‘/opt/lampp/lampp start‘ command, but he wanted an executable file in desktop to click, so every time he wants to start the server he double clicks that file and the server starts. This was easy for me, because I know how to create a file with .desktop extension, a file that is used to launch a specific application.

I created a Bash script like shown in Figure 1 and started thinking about the file launcher. The first line of the Bash script shown below is the shebang line, which tells the system what interpreter to use, the second line assigns the variable start to our command and the third line echoes the result of the ‘/opt/lampp/lampp start’ command when it is executed.

Figure 1

Before creating the launcher we should make our bash script executable with chmod u+x command, like shown in Figure 2.

Figure 2

We need an icon for our launcher so I downloaded one image from Google Images. What do you do next? Open your favorite text editor and copy paste the code below:

[Desktop Entry]

Version=x.y

Name=ProgramName

Comment=This is my comment

Exec=/home/alex/Documents/exec.sh

Icon=/home/alex/Pictures/icon.png

Terminal=false

Type=Application

Categories=Utility;Application;

I think this piece of code is self explanatory, but it deserves a simple explanation:

  1. Version: The version of the .desktop file
  2. Name: The name of the application. You can put the name you like here.
  3. Comment: The comments is used to describe your program. What is the purpose of your program?
  4. Exec: Put the path of the file you want the launcher to execute. For example, /home/oltjano/Desktop/:p.sh
  5. Icon: Icon of your launcher. Put the path of the image you want to use for the icon.
  6. Terminal: This line is used to specify if the application should run in a terminal window or not

Now we specify the path of the file we want to execute and the path of the icon for our file, like shown in Figure 3 and in Figure 4.

Figure 3

Figure 4

The file I want to execute is server.sh and I will use SL383952.jpg as an icon for the launcher. Save this file with aname.desktop and change its permissions to executable , like shown in Figure 5.

Figure 5

You can specify the version of the desktop file as well but it is not necessary. You can create your own bash scripts for your specific tasks and use them.

This article was a short introduction to desktop files and how to create them in order to make your life easier. This a simple example that shows the basics of creating a launcher, but I think it is enough for a good start.

For questions please refer to our Q/A forum at : http://ask.unixmen.com/

Share this Article: Facebook24Google+10Twitter14LinkedIn0Reddit0StumbleUpon0