Adding A New Desktop Shortcut

Create a new text file called yourname.desktop in the /home/pi/Desktop/ directory, e.g. /home/pi/Desktop/yourname.desktop

It should contain the following:


[Desktop Entry]
Name=My Name
Comment=My application which does this
Icon=/usr/share/pixmaps/openbox.xpm
Exec=/usr/bin/leafpad
Type=Application
Encoding=UTF-8
Terminal=false
Categories=None;

 

Name – The name you want displayed

Comment – Your comment

Icon – A file to use for the icon.  Your own or have a look in the /usr/share/pixmaps/ directory for something suitable.

Exec – The executable (can include sudo if your executable uses the IO). Can be the name of an executable program, or more complex, e.g. Exec=lxterminal –command "less /root/README.TXT"

Executing A Command In LX Terminal

The following will open LX terminal, wait for 5 seconds and then it will close:



[Desktop Entry]
Name=Name to be shown on desktop
Comment=My comment
Icon=/usr/share/pixmaps/openbox.xpm
Exec=lxterminal -t "Tile to display" -e sleep 5
Type=Application
Encoding=UTF-8
Terminal=false
Categories=None;

LX Terminal will auto close once the command is complete.  You can't give more than 1 command in the -e launch options (you can't give it "-e dosomething ; sleep 5" for instance as a way to make it hold showing the result after dosomething. 

Stopping The LX Terminal Auto Closing Or Doing Multiple Things

The simple way to get round the Lxterminal only being able to take one command is to have it run a bash script.

The .desktop file

[Desktop Entry]
Name=Name to be shown on desktop
Comment=My comment
Icon=/usr/share/pixmaps/openbox.xpm
Exec=lxterminal -t "Sending Crack The Code MAIN Leader Board To Internet" --working-directory=/home/pi/projects/scripts/ -e ./myscript.sh 
Type=Application
Encoding=UTF-8
Terminal=false
Categories=None;
The .sh script

#!/bin/bash

echo "Starting upload of database"
read dummy
echo "next"
mysqldump -h localhost -u user1 -p123456789 mydatabase tbl_universities | mysql -h mydomain.com -u user1 -p123456789 mydatabase
echo "Complete. Press return to exit"
read dummy

Remember to set the files permissions so it is executable (right click > properties in the file manager)

 

 

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

  1. Frank Slade

    6 years ago

    Yo thanks holmes this tutorial is dope, made a shortcut for NetSurf works fine now.

  2. Daniel C Kline

    6 years ago

    For other newbies (I resemble that remark), here is a quick solution that makes life easier. I created a desktop shortcut:
    [Desktop Entry]
    Name=Python 3 – root
    comment=Integrated Development environment for Python 3
    TryExec=/usr/bin/idle3
    Exec=sudo idle3
    icon=/usr.share/pixmaps/idle3.xpm
    Terminal=false
    Type=Application
    StartupNotify=true

    Create it with the text editor and save it to ‘home/pi/Desktop’. I saved mine as idle3Plus. Now when it executes, it will run the ‘sudo idle3’ command to launch as a root. Then you can use the gpio libraries and debug without needing to keep s separate terminal window open.

  3. dfrag

    6 years ago

    how do you create a link to a location on the hard drive. I tried the following but it didn’t work.
    [Desktop Entry]
    Type=link
    Name=www
    Comment=Link to the www folder
    Exec=%u
    URL=/var/www/

    I have also tried without the Exec line and it still doesn’t work.

    1. Mc Ondo

      6 years ago

      This will open file manager into /etc

      [Desktop Entry]
      Type=Application
      Name=Open folder
      Icon=system-file-manager
      Name[en_GB]=File Manager
      GenericName=File Manager
      GenericName[en_GB]=File Manager
      Comment=Browse the file system and manage the files
      Comment[en_GB]=Browse the file system and manage the files
      Categories=FileManager;Utility;Core;GTK;
      TryExec=pcmanfm
      Exec=pcmanfm /etc
      StartupNotify=true
      Terminal=false
      MimeType=x-directory/normal;inode/directory;

  4. Carol

    6 years ago

    it is possible to have The Pi Store downloads show up on desktop or in the Menu if I’m using Raspbian OS?

  5. gcolbourn

    6 years ago

    I’ve tried this but when I open them, they just open the text file for editing! How does it turn into a desktop shortcut?

    1. Melrick Nicolas

      6 years ago

      save it as .desktop

    2. Sr Viejo

      5 years ago

      I think the problem is that [Desktop Entry] was not included in the file text.

  6. sbignewski

    4 years ago

    Love it when stuff just works.

    Many thanks!!

  7. Olivier

    4 years ago

    Hi,

    Thanks for the tutorial, really helpful!

    I doing a shortcut to launch Alexa (voice assistant)
    I must have 3 different terminal windows open in order

    By now, I’, able to open it but one by one and keep it open!

    Here my file Alexa.desktop
    [Desktop Entry]
    Name=Alexa ON
    Comment=Switch Alexa ON
    Icon=/usr/share/pixmaps/alexa.xpm
    Exec=lxterminal -t “Launch Alexa” –working-directory=/home/pi/Desktop/alexa-avs-sample-app/project/ -e ./T1.sh
    Type=Application
    Encoding=UTF-8
    Terminal=true
    Categories=None;
    X-KeepTerminal=true

    and here my T1.sh
    #!/bin/bash
    echo Run the web service for authorization – DO NOT CLOSE THIS WINDOW
    # open a child window, run two commands in it, and leave the child window open
    cd ~/Desktop/alexa-avs-sample-app/samples && cd companionService && npm start
    echo “keep this open”
    # leave the parent window open
    read

    it the same for T2.sh and T3.sh

    How can I open 3 different terminal windows with only one shortcut?

    Thanks

  8. unusual computers

    4 years ago

    Thanks very much for this, found it very useful recently.
    A small correction though, you say:

    > You can’t give more than 1 command in the -e launch options (you can’t give it “-e dosomething ; sleep 5” for instance as a way to make it hold showing the result after dosomething.

    There is a way to make it execute more than one command by executing a shell and passing the commands to be executed as an argument. If you need the shell to be interactive, you can pass the shell command itself to lxterminal. For example I successfully run this:

    Exec=lxterminal -t “Installing radio rough” -e sh -c “cd ~/Desktop ; wget https://goo.gl/sKhgsG -O ~/Desktop/rasp_radio_rough_install.sh ; sudo chmod a+x ./rasp_radio_rough_install.sh ; ./rasp_radio_rough_install.sh ; sudo rm ./rasp_radio_rough_install.sh ; sleep 20″

    1. Adam

      4 years ago

      Thanks for the tip!

  9. CommotionWhales

    6 months ago

    Does anyone have one for reddit? Twitter,youtube,tiktok or anything like that?

  10. burner

    5 months ago

    Doesn’t exactly work for rPi Buster, gives a pop-up to select t o ‘execute’, ‘execute in terminal’, ‘open’, or ‘cancel’.

    1. LDMaughan

      4 months ago

      To stop that annoying pop-up you need to change a setting in File Manager

      1, Open File Manager
      2, Click on “Edit” on the toolbar
      3, Select “Preferences” from the drop down list
      4, Tick box that says “Don’t ask options on launch executable file”

      This took me ages to discover! haha

  11. K.R. O'Connell

    3 months ago

    excellent the comments are as good as the actual article
    years i have been looking for that answer to “burner”s question
    re Pi Buster and its annoying pop up????
    Well done everyone!

Comments

Your email address will not be published.