How can I create a application launcher for a .sh file?

20,065

Solution 1

Instead of linking directly to the .sh file create an application launcher as follows:

  • Right click on your desktop
  • Choose "Create Launcher..."
  • Change "Application" to "Application in Terminal" in the drop down box.
  • Give it a name like "Idea"
  • Enter the command like this /path/to/script/idea.sh
  • Add a comment if you like, it will show up when you mouse hover over it if you move the launcher to a menu bar.

Then when you click the launcher a terminal window will open and the command will run in there.

If you don't want to open a terminal to see any output, just use "Application" instead of "Application in Terminal".

You may have to edit the desktop file with something like gedit to add the "Path" of the script. Like This:

#!/usr/bin/env xdg-open

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon[en_US]=/home/kurt/Games/dontstarve/dontstarve.xpm
Exec=/usr/games/dontstarve/bin/dontstarve.sh
Path=/usr/games/dontstarve/bin
Name[en_US]=Dont Starve
Name=Dont Starve
Icon=gnome-panel-launcher

Solution 2

Why not just configure Nautilus to execute by default?

Under Nautilus goto Edit->Preferences->Behavior and click:

"Run executable text files when they are opened"

Solution 3

Richard's solution does not work for the Unity Desktop which recent Ubuntu versions use by default. To easily create shortcuts in unity you can use the "Main Menu" aka alacarte application which lets you edit programs. Just click the appropriate category and then "Create Item".

Solution 4

I Wanted to make it easier to launch "Dont Starve" for my kids. I started the program with /usr/games/dontstarve/bin/dontstarve.sh in a terminal, but wanted it in the applications menu.

I added a menu item with Alacarte but it would not work because it was a .sh file.

After many searches, I figured I needed to specify the path for the script.

Add path as explained in Desktop Variables

I located the launcher alacarte-made-51cc077a-58af-11e3-a764-00252267190b.desktop in ~/.local/share/applications/ and modified it by adding the path line.

Now Launcher file looks like this:

#!/usr/bin/env xdg-open

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon[en_US]=/home/kurt/Games/dontstarve/dontstarve.xpm
Exec=/usr/games/dontstarve/bin/dontstarve.sh
Path=/usr/games/dontstarve/bin
Name[en_US]=Dont Starve
Name=Dont Starve
Icon=gnome-panel-launcher

Works like a champ. I Hope this helps someone else. ( I actually run Mint 15 Olivia based on Ubuntu Raring )

Share:
20,065

Related videos on Youtube

OscarRyz
Author by

OscarRyz

Updated on September 17, 2022

Comments

  • OscarRyz
    OscarRyz over 1 year

    I have this run.sh file, and I've create a symbolic link into my desktop.

    When I double-click on it the file the following dialog appearsr

    And I have to click on "run" each time. How can I create a link that runs by default?

  • OscarRyz
    OscarRyz almost 14 years
    I wish I could add a non-svg image to the icon created. The rest worked perfectly Thanks.
  • OscarRyz
    OscarRyz almost 14 years
    Mhh.. strange, once created, I could associate the png icon Now it looks like this: yfrog.com/5gscreenshot20100817at719p Nice!
  • uuu777
    uuu777 over 13 years
    probably not something which most people want to suggest as default, but nevertheless very informative, it can be useful to know that it's possible.
  • amorfis
    amorfis about 13 years
    This works. However, when I remove icon from my desktop, it disappears also from launcher. How can I make it stay in launcher when I get rid of it from desktop?