29

Im trying to make a shortcut to login my ssh server:

ssh x.x.x.x

I made the following file:

ssh_home.sh

Made it executable:

sudo chmod +x ./ssh_home

Checked by right clicking properties to check if it was executable and it was..

But whatever I do, when double clicking it, it will launch gedit. I tried "Open With" but no terminal app is shown there. I searched the net but only found a way to link to the file while not integrating it in one "shortcut file"

  • 2
    Did you add #! /usr/bin/sh at the beginning of the file (the first line)? – Misery May 23 '13 at 11:50
  • Out of interest, what version of Ubuntu are you running? In principle it should be just a case of marking the file as executable in Properties/Permissions, but on 13.04 this seems not to work for me (even directly on the .sh file, with #! /bin/bash at the start...) – Jez W May 23 '13 at 11:59
  • Also check owner and permissions. Does user clicking it have permission to run it? – Misery May 23 '13 at 12:04
  • 1
    Your commands can't be correct - You're referring to ssh_home.sh and /ssh_home, which are not the same files. – l0b0 May 23 '13 at 12:04
  • 1
    @Misery: It's /bin/sh, not /usr/bin/sh. (/usr/bin/sh will happen to work on systems where /bin and /usr/bin are the same directory; I don't think that's the case for Ubuntu>) – Keith Thompson Jul 10 '15 at 21:05
44

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

  • 2
    This should be the accepted answer IMHO. I was getting rather frustrated trying to figure out why I could not run the shell script from Nautilus. – David Baucum Aug 16 '14 at 0:12
  • What is Files menu? Never seen it. – IgorGanapolsky Mar 29 '15 at 16:27
  • Worked. Right click on my shell script in the file browser. Created link. Then drag and dropped link to desktop. Also did the step above in file browse -> Preferences->run instead of view. – maxweber Apr 16 '15 at 15:33
  • 3
    One complication is that this affects all executable files. (That might be what you want.) – Keith Thompson Jul 10 '15 at 21:06
  • Great answer! On Ubuntu 18.04, I set it to 'Ask what to do', so I can choose to run or display it every time I double click such a file. Thanks! – MS Berends Feb 10 at 16:31
32

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
  • 1
    This method IS working but I prefer a 1 file solution... – michel May 23 '13 at 14:16
  • 6
    @michel If all the script does is run ssh host, you don't need the script, just change the Exec line to Exec=ssh host. – geirha May 23 '13 at 18:33
  • 1
    This is the only solution that worked for me. – Aviad P. Aug 26 '15 at 16:50
  • I get Untrusted application launcher message box and it doesn't run my command. – Matt Dec 27 '18 at 20:00
  • @Matt try right clicking on the icon, go to Properties > Permissions then select Allow executing file as program. Also if you copy and pasted the text above into your file, make sure there isnt any trailing whitespace after the lines. That may cause your error message. – Olivia Stork Jan 18 at 18:38
2

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...

  • For my taste also... – Marecky May 10 '17 at 16:37
1

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.
  • Also you can change the icon of the link too. Right-click it, select Properties, click the default icon in the upper left part of the properties window, and so just navigate until you find the image your want to be the icon. – Brian Hellekin May 24 '17 at 4:07
0

I'd say the easiest way to add a shell script to the shortcuts would be to add the .sh file to the home directory. Once copied to the home directory just go to custom shortcuts and add the command sh yourfile.sh

This was my work around hope it helps you

protected by Community Feb 2 '18 at 16:52

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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