Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a shell script that runs a GUI application on Ubuntu 12.04.

The way I'm currently running the application is that I open the terminal and go to the directory that contains that file, then do sudo ./shellScriptFileName which runs just fine, however I have two problems, one is that this takes so much time so I would like to add a shortcut in the launcher, second is that the terminal needs to stay open, which is a pain (hopefully this won't be a problem after I'm able to run it from the launcher.

Clarification: I would like for the terminal to be closed when my application starts running.

share|improve this question
you may create a shortcut in the launcher and with sudo ./ShellScriptFileName & to make it running in the background – vicd May 18 '12 at 1:44
How can I create the shortcut in the launcher? – Roronoa Zoro May 18 '12 at 1:45
See my answer :) Your's requires an additional step since you want the terminal to remain open. – izx May 18 '12 at 2:11
Here is how – vicd May 18 '12 at 2:11
@izx, nice answer though, but I'm afraid that he mentioned it's a pain with the terminal remains :P, he wants it's gone and silent. – vicd May 18 '12 at 2:15
up vote 1 down vote accepted

It seems that you haven't got this issue done yet, have you visited the "how to" link which I provided in the comment above? Click Me

If you check that you should get this problem solved in several ways, cool and nice. To be simple, I'd like to recommend a "dummy" way to make it works for you.

  1. Open your terminal and type sudo apt-get install gnome-panel
  2. When the installation is done, type gnome-desktop-item-edit --create-new ~/Desktop, this command will display a popup "Create launcher" dialog, shown as below enter image description here

    customize your settings(Name,Command,Icon etc.)

  3. After step 2, you will get a shortcut(it is actually named *.desktop, depends on your setting), feel free to put it in any folder you wish, then drag and drop it to the launcher.

That's it, enjoy your new baked shortcut :-), hope it helps.

share|improve this answer
Thank you but I still have some problems: 1) in the Type option, if I choose Application, the program runs then exits immediately, however, if I choose Application in Terminal, it works but the terminal opens and stays open - I'm not sure why this is happening, but if that's the only way to do it, I guess I'll just keep the terminal open :( 2) My second problem is that I don't think I'm in root mode when following your instructions, I can't save any files (through the application) when running it using your method – Roronoa Zoro May 19 '12 at 10:40
if you need to interact with your script, it's better to let the terminal remains, otherwise just let it running in the background(add the & at the end of your command) to get its tasks done. For the root permission, sudo your_command. – vicd May 20 '12 at 12:10

Here are the steps:

1. Creating the interactive caller script

Since you want to execute the script and then have the terminal remain in an interactive mode, we need to use a special caller script, which in turn requires expect. We'll assume the script you want to execute is called

  • Install expect with sudo apt-get -y install expect
  • Create the caller script with this format:

    #!/usr/bin/expect -f 
    spawn -noecho bash           # create a shell
    expect "$ "                  # wait for prompt
    send "cd /path to script\n"  # your script directory
    send "./\n"           # your script name
    interact                     # switch to interactive mode
  • Make the caller script, say, executable with

    sudo chmod +x /path/to/

2. Creating the Launcher

  • Press Alt+F2, and type gksudo gedit /usr/share/applications/TestSH.desktop, where TestSH is whatever you want to call your launcher icon.
  • The file is of the following form:

    [Desktop Entry]
    Version=1.0          # your script version
    Terminal=true        # you want a terminal, so...
    Icon=                # can be a built-in (/usr/share/icons)
                     # or a custom file, SVG or PNG
    Name=TestSH          # Whatever you want to call it
    Comment=           # description
    Exec=/path/to/ # Path to caller script
  • Finally, make sure the actual script is executable, with sudo chmod +x /path/to/

  • Close the editor, and search for "TestSH" (script name) in the HUD; you will see the icon, which you can click on, and also drag to the launcher or desktop to add it there.
share|improve this answer
I apologize for the misunderstanding. I actually want the terminal to close. I was talking about the current method that I'm using, which keeps the terminal open... – Roronoa Zoro May 18 '12 at 3:49

Making the terminal stay open afterwards is not a very smooth process, but here is what I suggest:

Make a new script with the following contents: gksudo /path/to/shell/script and save it to your desktop. Add the terminal to the launcher. To open the program, open the terminal from the launcher and clik'n'drag the script from the desktop to the terminal.

Or, if you don't necessarily need the terminal open after the program is finished, make a script as above, save it to any directory, and follow this guide to turn it into a launcher icon:

I wish that process were a bit smoother, but hey, that's why I use Kubuntu...

share|improve this answer
I just tried to create a new script as you described (gksudo path/oldScript), I also changed its access and gave it execution permission (chmod +x, but I'm still having a problem. When I run the newScript, I type the password for the root, then my application starts then exits immediately. By the way, if I try to double-click oldScript, and I click on the option Run, I get the same result; my program starts then exits immediately, however, if I click the option Run in Terminal, it works fine... – Roronoa Zoro May 18 '12 at 4:24
gksu would be the right command to run a GUI app. Did you try to include this in your script? – Takkat May 18 '12 at 7:42
@Takkat, I just tried gksu; same results. I'm wondering why my application works fine when I double-click the original script and choose Run in Terminal, and why it doesn't work when I double click the new script (gksudo or gksu /path/originalScript) and again, choose Run in Terminal... Running my application by double-clicking the original file won't be useful to me, first it's not root access, and second I need to add it to the launcher... – Roronoa Zoro May 18 '12 at 8:23
In case I wasn't clear in my last comment. My situation is the following: I created a new script gksudo path/oldScript, then I followed the guide to turn it into a .desktop file, but when I double-click on the .desktop file, I enter the password, then my application starts and immediately closes. I think I have a problem with the new script. Although I changed the access to execution permission (chmod +x, I'm still not able to run my application through the new script, whether I choose Run, or Run in Terminal. BTW Run in Terminal works on the old/original script. – Roronoa Zoro May 18 '12 at 8:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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