How to add a shell script to launcher as shortcut

290,023

Solution 1

  1. Create *.desktop file, location depends on if it is for personal use or all users. If these directories do not exist, create them.

For personal use , ~/.local/share/applications

gedit ~/.local/share/applications/name.desktop

For all users, /usr/local/share/applications/ (or /usr/share/applications/ depending upon your system).

sudo -i gedit /usr/share/applications/name.desktop
  1. Paste below text

    [Desktop Entry]
    Type=Application
    Terminal=true
    Name=unmount-mount
    Icon=/path/to/icon/icon.svg
    Exec=/path/to/file/mount-unmount.sh
    

    edit Icon= and Exec= and Name=

    Also Terminal=True/false determines whether the terminal opens a window and displays output or runs in the background

  2. put this in unity panel by dragging it from files manager

logic is very simple that unity panel allows *.desktop files as launcher though I haven't tried it because I use Natty.

Solution 2

What @vipara said is mostly correct, except that I also found /usr/local/share didn't work for me. Also, you will need to run sudo update-desktop-database after adding this file in order to refresh the launcher apps. Also, there is a much easier way to create the .desktop files. First, make sure you have the gnome-panel installed (it was pre-installed on my 12.04 Ubuntu):

sudo apt-get install --no-install-recommends gnome-panel

Once you have this command, then you can run:

gnome-desktop-item-edit ~/Desktop/ --create-new

This will bring up a nice GUI window where you can select the application, icon, etc. It will dump the .desktop file on your desktop (or wherever you direct it), so you'll still need to sudo mv it to the applications folder and update the desktop database afterwards

Launchers are saved in /home/myusername/.local/share/applications

Share:
290,023

Related videos on Youtube

Nirmik
Author by

Nirmik

A true LINUX lover and APPLE fan!! An aspiring OS DEVELOPER i love to work on linux. :) With an encounter with linux from the past 1year,I have definitely succeded in creating a LINUX community around with many friends. Love LINUX for every bit of it..!! :) <3

Updated on September 18, 2022

Comments

  • Nirmik
    Nirmik over 1 year

    Possible Duplicate:
    How can I edit/create new launcher items in Unity by hand?
    How can I create launchers on my desktop?

    I want to add some shell scripts in my launcher as shortcuts..

    They are located deep inside and i have to navigate to it every time to execute them...

    I tried this link where the 2nd answers seems to solvee it but as said in comments neither can i find any option to add a launcher..

    I guess it existed in 11.04 with a "+" button on launcher but i use 12.04.

    So how do i get this working?? And i need those commands everytime for sure..!

    • Mateo
      Mateo almost 12 years
      Relevant link, the right click for creating launcher is now gone, askubuntu.com/questions/64222/…
    • jrh
      jrh almost 5 years
      If you find that you can't run scripts even after checking these answers, check out this link; users running other flavors of ubuntu like Linux Mint, Mate, Xubuntu, etc may need to do sudo ln -s /usr/bin/mate-terminal /usr/bin/gnome-terminal, I was never able to execute anything in a terminal from a launcher without that.
  • Nirmik
    Nirmik almost 12 years
    okay it worked for a terminal exicuting .sh file...now i want to add another bash file which has a gui and thus is not "Run in terminal".how to do that?? i tried changing terminal=false but it did not work...what should i do??
  • Nirmik
    Nirmik almost 12 years
    the sh file which uses gui is of the android emulator(SDK)...i want the above script to be edited such that i can run the graphical .sh file...i.e right now when i click on the file i have to select "run" and not "run in terminal"
  • Nirmik
    Nirmik almost 12 years
    here is the link---pastebin.com/aQ13uLHK
  • Rahul Virpara
    Rahul Virpara almost 12 years
    @Nirmik are you able to run this script by double click?
  • Nirmik
    Nirmik almost 12 years
    yes...i can...it actually starts a tool for sdk.then from the tools menu of that window i can start a virtual device...so i need to start that window...it has all its supporting files around..without those it obviously does not run...can i make a soft link to it and then make a *.desktop file of the softlink?? but the problem here is still "RUN" not "RUN IN TERMINAL"..will softlink solve the issue?? i'll try that too..
  • Rahul Virpara
    Rahul Virpara almost 12 years
    @Nirmik if you can run with double click on that script then the shortcut file created as above described works just fine. I use many applications which starts using shell script. here are the *.desktop content of some of them if you want to play with it. pastebin.com/E2hzYwGK
  • Rahul Virpara
    Rahul Virpara almost 12 years
    @Nirmik if Exec= is full path to script then you don't need to make soft link
  • Nirmik
    Nirmik almost 12 years
    hey the soft link worked...actually when i was direcly giving link to the .sh file,for some reason it was saying no such directory...and also,as i had thought,seting the terminal parameter to false makes it just "RUN"
  • Nirmik
    Nirmik almost 12 years
    actually thats what m confused with...as to why it was giving me an error of "no such file or directory" i had copy-pasted the path from the location bar... wierd...i'll again try the direct path way insted of softlink
  • Nirmik
    Nirmik almost 12 years
    Hey its working without the link...actually it was my mistake...the file name was not "android.sh" it was just "android".And me considering it as .sh file,i added the extension which gave me the appropriate error of "could not find"..!! :) its working now...and the "Terminal=false" makes it run directly into gui..!! :) THANX a lot for staying with me and helping me all the way long..! I appreciate your efforts..:) Thanx again :)
  • Rahul Virpara
    Rahul Virpara almost 12 years
    @Nirmik whether you use Terminal=true or Terminal=false it can always start gui(actually *.jar file in JVM). Terminal=false just hides terminal and script executes in background.
  • Nirmik
    Nirmik almost 12 years
    Yeah exactly...thats what i wanted to say...with "Terminal=true" there will always be a blank terminal open...and i many-a-times accidently close the rong ones... :p
  • xchg.ca
    xchg.ca over 10 years
    An Ubuntu 13.10, you don't have to do anything extra like you mentioned, gnome-desktop-item-edit does it for you, and it appears on you desktop automatically.
  • loloof64
    loloof64 almost 10 years
    Sorry for the late reply : I've tried with IntellijIdea shell script, which I added into classpath, but in the desktop icon file WE MUST PUT THE ABSOLUTE PATH !
  • ᴠɪɴᴄᴇɴᴛ
    ᴠɪɴᴄᴇɴᴛ almost 10 years
    In Ubuntu 14.x gnome-desktop-item-edit isn't pre-installed. After creating the desktop configuration file, just drag it to the launcher (Dock). (You can also select a custom icon: right-click the desktop configuration file, select Properties ..., click on the icon in the dialogue, select an image file.)
  • IgorGanapolsky
    IgorGanapolsky about 9 years
    I get an error: gnome-desktop-item-edit ~/Desktop/ --create-new gnome-desktop-item-edit: file:///root/Desktop does not have a .desktop or .directory suffix
  • IljaBek
    IljaBek over 6 years
    find /usr/share/icons -iname *usb* will give a list of icons to use ;)
  • Ahmed Hamdy
    Ahmed Hamdy over 6 years
    Not working with Ubuntu 17.10
  • Mitch
    Mitch about 6 years
    On 18.04 I get errors after running sudo update-desktop-database and the icons don't show up in the dock: Error in file "/usr/share/applications/org.gnome.font-viewer.desktop": "font/ttf" is an invalid MIME type ("font" is an unregistered media type) Error in file "/usr/share/applications/org.gnome.font-viewer.desktop": "font/otf" is an invalid MIME type ("font" is an unregistered media type)
  • Tom
    Tom about 5 years
    How can this possibly be the correct answer in 2019?! I mean it does work, but really, i'm trying to add a shortcut to a GUI...
  • Pawel Debski
    Pawel Debski over 4 years
    Works like a charm... Ubuntu 18 LTS, Gnome
  • rubo77
    rubo77 about 4 years
    This doesn't work in Ubuntu 19.10
  • Reeshabh Ranjan
    Reeshabh Ranjan almost 4 years
    Works in Ubuntu 20.04 LTS as well
  • Frederiko Cesar
    Frederiko Cesar over 3 years
    It worked, but after I change the file permissions to 644 with chmod 644 file.desktop and I also had my Exec= path not right, and when I fixed it to the correct path, the "Allow launching" appeared and I was able to add it as a favorite in the launcher.
  • Ashton
    Ashton over 3 years
    make sure you have the permission. askubuntu.com/questions/1038651/…
  • Lawhatre
    Lawhatre almost 3 years
    Got gnome-desktop-item-edit: command not found after sudo apt-get install --no-install-recommends gnome-panel & gnome-desktop-item-edit ~/Desktop/ --create-new on ubuntu 20.4
  • treyiii
    treyiii almost 3 years
    how come this works and some time i don't
  • dompie
    dompie almost 3 years
    On Ubuntu 18 LTS it is not possible to drag .desktop file into launcher