68

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"

kiri
  • 27,676
  • 16
  • 81
  • 117
michel
  • 697
  • 1
  • 5
  • 4
  • 4
    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
  • I've just added what you suggested file contains now: #! /bin/bash shh x.x.x.x But still no succes.. I'm using ubuntu 13.04 64bit I'll try to make the shh_home.desktop but I rather just keep one file because I don't want to have to link to such a small file with so little code.. – michel May 23 '13 at 14:07
  • possible duplicate of [Apply icons to bash scripts](http://askubuntu.com/questions/60667/apply-icons-to-bash-scripts) – bain May 23 '14 at 12:00
  • possible duplicate of [How do I make a custom launcher for terminal applications?](http://askubuntu.com/questions/34597/how-do-i-make-a-custom-launcher-for-terminal-applications) – dobey Jul 01 '14 at 19:39
  • 2
    @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
  • Possible duplicate of [How to execute a script just by double clicking like .EXE files in Windows?](http://askubuntu.com/questions/138908/how-to-execute-a-script-just-by-double-clicking-like-exe-files-in-windows) – Matthew Read Mar 08 '16 at 23:29

6 Answers6

60

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
Olivia Stork
  • 157
  • 7
Cyril Laury
  • 916
  • 6
  • 6
57

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

muru
  • 193,181
  • 53
  • 473
  • 722
Peter
  • 709
  • 5
  • 6
3

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

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.
muru
  • 193,181
  • 53
  • 473
  • 722
  • 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 04:07
1

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

0

Ubuntu 20.04

open file manager (aka Nautilus) click hamburger menu, top right (three horizontal bars) choose Preferences click Behaviour tab under Executable Text Files, choose your preference. (Ask What to do lets you choose each time and file)

Peter Addison
  • 13
  • 1
  • 6