How to execute sh script from a desktop shortcut?

I know this is a while ago but though if someone else asks I have this answer.

  1. Open nautilus
  2. Files menu -> behaviour tab
  3. Run executable text files when they are opened

In later versions this option is found at: Files menu -> Edit -> Preferences -> behaviour tab

In Ubuntu 14.10 move the mouse to the top of the screen and the File, Edit etc... Menu bar appears. Click EDIT -> Preferences -> Behaviour tab


I think it would be better to use a launcher file for your script by creating a ~/Desktop/ssh_home.desktop file with the following contents:

[Desktop Entry]
Version=1.0
Exec=/home/yourname/bin/ssh_home.sh
Name=SSH Server
GenericName=SSH Server
Comment=Connect to My Server
Encoding=UTF-8
Terminal=true
Type=Application
Categories=Application;Network;

That way you will have a clickable icon which will launch your script.

You may have to also set the executable flag with chmod:

chmod +x ~/Desktop/ssh_home.desktop

The "trap" for me was that I searched via right-clicking on the file for a way to change the behaviour (to have a script run instead of opened in gedit). Don't right-click ! Rather open from the "regular" menu-bar:

Edit-Preferences-Behaviour and change to "run" or "ask each time".

Comment: For my taste there should be a way to run a program via right-clicking too. Especially since right-clicking leads to the menu "open with", which makes you search for "open with bash", however "bash" is not included as an option...


imo the simplest answer is -

  1. Check that the .sh file works if clicked or run from its own directory.
  2. If it works there, right-click on it in Files aka Nautilus, select 'Make Link'
  3. This produces a file named 'link to xxxx.sh' in the same directory
  4. Drag this onto the desktop
  5. Rename it how you wish eg clean off 'link to' and 'sh', just leave the name, it will still work.