Page 1 of 2

Desktop 'shortcuts'

Posted: Tue Apr 10, 2012 6:16 pm
by bjackson60
Is there a way to make a Windows style desktop shortcut to run a shell script?

I made script to start the VPN, connect to a remote desktop and shut down VPN when finished. It works
great via command line. But it would be nice to just click an icon.

I am new to Linux so I don't know a whole lot. :oops:

Linux Mint 12 LXDE

Re: Desktop 'shortcuts'

Posted: Wed Apr 11, 2012 12:01 am
by M_Mynaardt
bjackson60 wrote:Is there a way to make a Windows style desktop shortcut to run a shell script?

I made script to start the VPN, connect to a remote desktop and shut down VPN when finished. It works
great via command line. But it would be nice to just click an icon.

I am new to Linux so I don't know a whole lot. :oops:

Linux Mint 12 LXDE
You can create a desktop icon, which is actually a text file. I've done that for a few icon short-cuts on my Lubuntu desktop.

Here's an example of the one I have that shows up as "Trash", the name of the file is app_trash.desktop so I can have a Trash desktop icon:

Code: Select all

[Desktop Entry]
Encoding=UTF-8
Name=Trash
Comment=Open Trash folder in PCManFM
Icon=/home/username/.extra-icons/trashcan-128x128(c).png
Exec=/usr/bin/pcmanfm trash:///
Terminal=false
Type=Application
"Name" is just what you see on the screen below the icon. But I've found in Lubuntu, that name can't be too long or it gets chopped at either end.

The key line is "Exec=/path/command". You have to do things a wee bit differently if it's a shell or bash file you want to execute. This is an example from another desktop Icon I have for running Nix Note; the free Evernote clone:

Code: Select all

[Desktop Entry]
Encoding=UTF-8
Name=Nix
Comment=RunNixNote
Icon=/home/username/.extra-icons/Nevernote-164x308.png
Exec=sh /usr/share/nixnote/nixnote.sh
Terminal=false
Type=Application
I had to mess about with this to get myself a set of short-cut icons I like. Including looking around for cool icons that suited my desktop. There are lots of sites for free icons about.

Note how you run the shell with "Exec=sh /path/shellname.sh"

Hope that helps get you started. It works fine for me!

Enjoy!
:mrgreen:

Re: Desktop 'shortcuts'

Posted: Wed Apr 11, 2012 6:36 am
by seppalta

Re: Desktop 'shortcuts'

Posted: Wed Apr 11, 2012 9:28 am
by bjackson60
Thanks! I'll play around with this when I get off work. :D

Edit: Couldn't wait! This works perfectly!!! Thanks M_Mynaardt :twisted:

Re: Desktop 'shortcuts'

Posted: Wed Apr 11, 2012 4:00 pm
by M_Mynaardt
bjackson60 wrote:Thanks! I'll play around with this when I get off work. :D

Edit: Couldn't wait! This works perfectly!!! Thanks M_Mynaardt :twisted:
No problem!

Now you've got a template for making whatever LXDE icons your heart desires!

Enjoy!
:ugeek:

Re: Desktop 'shortcuts'

Posted: Wed Apr 11, 2012 4:36 pm
by bjackson60
OK, now I have another problem that I don't understand. The shortcut worked like a charm. (Thanks again) But I noticed my script was not disconnecting from the VPN. I edited the script only prepending sudo to the existing line 'vpnc-disconnect'. When I saved the file I noticed the screen refreshed and the icon moved to a new location. The shortcut now does nothing when clicked. The script still works from the command line. Has editing the script file broken something :?:

Re: Desktop 'shortcuts'

Posted: Wed Apr 11, 2012 8:18 pm
by M_Mynaardt
bjackson60 wrote:OK, now I have another problem that I don't understand. The shortcut worked like a charm. (Thanks again) But I noticed my script was not disconnecting from the VPN. I edited the script only prepending sudo to the existing line 'vpnc-disconnect'. When I saved the file I noticed the screen refreshed and the icon moved to a new location. The shortcut now does nothing when clicked. The script still works from the command line. Has editing the script file broken something :?:
I know you can't do much about the order of icons on an LXDE desktop. You're sort of stuck with that. But that ought not affect whether or not they work.

Does your script file name have any spaces in it? Or the path it's in? Sometimes that's a problem. Try putting the entire shell scrip name, including the path, in quotation marks. That might help a bit.

I'm not an expert on scripts, though. I've limited experience with those. So if the problem is the script itself, I'm not sure how to fix that off the top.

Re: Desktop 'shortcuts'

Posted: Thu Apr 12, 2012 1:11 am
by bjackson60
It's driving me nuts! The script is working perfectly, but the desktop icon just doesn't. Oh well, I'll just command line it and go learn some more. :mrgreen:

Re: Desktop 'shortcuts'

Posted: Thu Apr 12, 2012 3:08 am
by M_Mynaardt
bjackson60 wrote:It's driving me nuts! The script is working perfectly, but the desktop icon just doesn't. Oh well, I'll just command line it and go learn some more. :mrgreen:
Maybe you might need to do this first:

Go to the directory that Shell file is in.

From the terminal, try one of the two commands:

Code: Select all

~$ chmod +x shell_name.sh
~$ chmod 755 shell_name.sh
One of those might work.

What do the contents of your .desktop icon file look like? If it worked once, there might just be an easily overlooked "oopsies" in there. I myself often get tripped up on little things that are easily overlooked.

And anyway, this is what you call learning by "trial and error" - which really means "mostly error"…
:cry:

The 'being driven nuts' bit sounds very familiar indeed! Been there, done that!
:?

Re: Desktop 'shortcuts'

Posted: Thu Apr 12, 2012 9:09 am
by bjackson60
I tried the chmod deal already, and checking permissions through the gui reports what I expected.

I did change the exec line to something bogus and it bitches about it when I run it, so it is obviously trying. I'm looking into that a little closer.