How do you create a desktop icon to start a program


16 posts
by computerpie » Sat Jun 30, 2012 12:52 pm
I want to run programs like vncviewer and open several instances. How can I create a desktop icon that will start programs? Like batch files in DOS.
For example now to start vncviewer i open terminal and type the command xvncviewer.

Thanks in advance.
Pi1>OS: Rasbian Pi2>OS:Xbian .63
1:HDMI>>DVI>>Flat Screen Monitor
2: HDMI>>Toshiba 37" LCD
1:ASUS Wired USB Keyboard and Mouse
2:Logitech wireless mouse, CEC remote
SanDisk SDHC C4 8GB SD
User avatar
Posts: 57
Joined: Wed Jun 20, 2012 10:55 pm
Location: USA
by JeremyF » Sat Jun 30, 2012 1:02 pm
I'm not at my Raspberry Pi at this moment, but if you right click the desktop, there should be an option for making a "launcher".

More easier, if it's multiple lines of code is to:

1) Open terminal
2) cd /home/pi/Desktop
3) nano [insertanamehere]
4) type up your commands, multiple lines are allowed (this is called bash scripting)
5) save by hitting control-x then a few other things
6) sudo chmod +x [thenameyouusedearlier]
7) Go to desktop
8) There should be a program you can double click on and that will launch

That's the way I would do it anyway.
{sig} Setup: Original version Raspberry Pi (B, rev1, 256MB), Dell 2001FP monitor (1600x1200), 8GB Class 4 SD Card with Raspbian and XBMC, DD-WRT wireless bridge
Posts: 516
Joined: Wed Jan 25, 2012 9:06 pm
by computerpie » Sat Jun 30, 2012 1:17 pm
Works great thank you! :D
Pi1>OS: Rasbian Pi2>OS:Xbian .63
1:HDMI>>DVI>>Flat Screen Monitor
2: HDMI>>Toshiba 37" LCD
1:ASUS Wired USB Keyboard and Mouse
2:Logitech wireless mouse, CEC remote
SanDisk SDHC C4 8GB SD
User avatar
Posts: 57
Joined: Wed Jun 20, 2012 10:55 pm
Location: USA
by Joe Schmoe » Sat Jun 30, 2012 1:28 pm
Of course, the correct answer to the question posted in the Subject line is:

I don't.
Never answer the question you are asked. Rather, answer the question you wish you had been asked.

- Robert S. McNamara - quoted in "Fog of War" -
Posts: 2779
Joined: Sun Jan 15, 2012 1:11 pm
by timothy3592 » Tue Jul 03, 2012 5:19 pm
This issue seems to be resolved, however I'll post a bit about creating a desktop launcher for people who click on this thread with just that goal in mind. The solution given to the original post is to create a shell script, and that works, but for those who want "the thing that looks like the Firefox logo that i click on to get online" or the like, a desktop launcher is more suitable. The pros are that launchers have icons, shell scripts don't; however launchers execute one command, not like a bat file or a shell script which generally execute a list of commands in sequence. Both files are just the right kind of text file. a launcher is formatted as follows.

[Desktop Entry]
Name="the name that displays under the icon on the desktop"
Exec="a single command with or without arguments to execute on double click"
Icon="/path/to/some/128pxX128px.png"
Comment="If I'm here i show in properties tab or something"

there are more. but the first four lines usually do it, save your launcher as filename.desktop and it will work as expected and if not tweak it a little and try again.
Posts: 64
Joined: Wed Jun 13, 2012 6:06 am
by BLL » Thu Jul 04, 2013 6:40 pm
Hi, I am trying to get a shortcut on the LXDE desktop to run a script file called 3g. Should be simple? I have created a file called 3g.desktop in /home/pi/Desktop, which has in it the following:

[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=3g
Exec=/home/pi/3g
Terminal=false
StartupNotify=true

You can double-click until domesday and it does precisely NOTHING!! God, isn't DOS/Windows simple in comparison!!!

Any offers on why it won't please?
Posts: 71
Joined: Fri Jun 07, 2013 2:30 pm
by sdjf » Thu Jul 04, 2013 8:00 pm
Uhm, you do not have a line giving an Icon there, what are you double clicking on?

Actually, I somehow managed to get icons dragged or copied onto my LXDE desktop many months ago, and they never open anything. I either use the menu that is the little thing that looks like an X in the lower taskbar, and that brings up a menu where clicking on items actually starts applications.

I never figured out how to get those desktop icons to do anything, and for sure do not know what I did to get them there in the first place, I was just fiddling around, not easy to repeat.

Do you have Openbox too, or LXDE? I am still befuddled about which of the panels/menus/etc are openbox vs. lxde, I just know which to click on. I uninstalled pcfman because it was useless to me.
FORUM TIP: To view just one person's posting history, sign in, click on their user name, then click on "Search User's Posts." || This Pi owner is running Arch on 512MB Model B.
Posts: 1297
Joined: Fri Mar 16, 2012 5:20 am
Location: California
by BLL » Thu Jul 04, 2013 8:19 pm
Hi, No icon line just gives you the standard one that looks like a sheet of paper with the corner folded. The scripts I want to run aren't in the menus as they are my scripts. I have only tried LXDE so far as I am very new to the RasPi. Why the LXDE people couldn't have had a rightclick menu option to create a shortcut is beyond me! It must be something most people need to do!

All I want to do is double-click on an icon and for it to run my script!!

It does seem to me that everything in Linux is made as complicated as possible, as though they want to put people off!!
Posts: 71
Joined: Fri Jun 07, 2013 2:30 pm
by sdjf » Thu Jul 04, 2013 10:18 pm
It is not that they want to put people off, we actually do a lot of proselytizing but the developers don't always decide to build things in, it takes other applications that are supplementary.

You might want to install openbox in addition to lxde because that may add the things you are looking for.

Also, maybe what you need is lxpanel, did you install that? It is a pretty important part.

Here is a list of all the lxde applications I installed, not all are necessary for the amenities you want, but are probably worth installing to see how much they might help:

lxsession lxde-icon-theme lxde-common
lxmenu-data lxlauncher lxinput
lxdm lxappearance lxappearance-obconf
lxsplit lxterminal lxtask
lxshortcut lxrandr lxpanel
FORUM TIP: To view just one person's posting history, sign in, click on their user name, then click on "Search User's Posts." || This Pi owner is running Arch on 512MB Model B.
Posts: 1297
Joined: Fri Mar 16, 2012 5:20 am
Location: California
by BLL » Fri Jul 05, 2013 10:27 am
Thanks for the info - I'll try those and see. The LXDE was installed from the original image, but I haven't installed anything else to do with it.

Thanks again.
Posts: 71
Joined: Fri Jun 07, 2013 2:30 pm
by BLL » Fri Jul 05, 2013 10:38 am
Hi, Still no-go. Most on the list of yours were already there. Only lxlauncher and lxappearance-obconf weren't. lxdev and lxsplit don't appear to be known. Now it's Openbox, I guess!
Posts: 71
Joined: Fri Jun 07, 2013 2:30 pm
by BLL » Fri Jul 05, 2013 10:44 am
Hi again. I give up! Openbox already there! Still can't launch my scripts!
Posts: 71
Joined: Fri Jun 07, 2013 2:30 pm
by wesper » Fri Jul 05, 2013 11:13 am
Hi,

What is "/home/pi/3g" supposed to be doing? Are you sure that it has not been executed everytime you clicked the icon? If it is not opening a window or writing something to a file you won't notice that it has been executed. Have you made sure that it is "executable" (chmod +x /home/pi/3g)? Have you tried to run it in a shell and seen what it did there, any printouts?

/ Per-Erik
Posts: 1
Joined: Fri Jul 05, 2013 11:00 am
by BLL » Fri Jul 05, 2013 12:11 pm
The file copies a file and then calls for a reboot. I think this is where the problem lies as to run it from a command line needs sudo because of the reboot command. I guess therefore that that's why it won't run from the 3g.desktop file. I don't know how one can do it from the Exec entry in the .desktop file, therefore.

I have done the chmod to it.
Posts: 71
Joined: Fri Jun 07, 2013 2:30 pm
by sdjf » Sun Jul 07, 2013 5:11 pm
Another solution would be to put sudo into the commands in your script that require those permissions. Have you tried that?

You could run the script as user pi but then have certain commands inside the script be prefaced by sudo.

I think you might need to separate this issue of sudo from whether you can get any script at all to simply run from a desktop icon.

You could move 3g to 3g.bak and call another script 3g and have it write something to disk when it executes successfully.

echo this script has run > ~/testinglauncher.txt

If that is the only command inside the script, and launching it works then you know you can launch a script, and just need to tweak your real 3g script so it will succeed in doing what you want.
FORUM TIP: To view just one person's posting history, sign in, click on their user name, then click on "Search User's Posts." || This Pi owner is running Arch on 512MB Model B.
Posts: 1297
Joined: Fri Mar 16, 2012 5:20 am
Location: California
by douglaslourey » Thu Dec 05, 2013 6:24 am
Creating a desktop shortcut seems to be about as easy as flying to the moon.
I wish to create a desktop shortcut to /usr/bin/raspi-config so I don't have to remember the name of the configuration program six months from now.
I've created a file named config.desktop in my home /Desktop folder. Here are the contents:
[Desktop Entry]
Type=Application
Comment=Raspi-Configuration Tool
Name=Raspi-Config
Exec=sudo "/usr/bin/raspi-config" (tried /usr/bin/raspi-config, "sudo /usr/bin/raspi-config")
Terminal=false (tried true)
StartupNotify=true (tried false)
And yes, I made the file executable.
Nothing seems to work. I'm guessing there is a secret to running this type of program from a desktop shortcut. It would be nice if there was a recipe for creating desktop shortcuts that cooked up nice every time.
Posts: 4
Joined: Wed Nov 13, 2013 1:43 am