Desktop Shortcut for Python Script on Raspberry Pi - Makergenix

This tutorial is about how to create a desktop shortcut for a python script/program on your Raspberry Pi. This shortcut allows you to create links to programs in any folder, desktop or other locations on the Pi. Desktop shortcuts save your time and also provides an easy way to reach out to your required file.

Desktop Shortcut for Python Script on Raspberry Pi - Makergenix
Desktop Shortcut for Python Script on Raspberry Pi

Desktop Shortcut for Python Script on Raspberry Pi - Makergenix

This tutorial is about how to create a desktop shortcut for a python script/program on your Raspberry Pi. This shortcut allows you to create links to programs in any folder, desktop or other locations on the Pi. Desktop shortcuts save your time and also provides an easy way to reach out to your required file. 

 

Create a Python Script

Let’s start with creating the program first. Write a Python program using any Python Editor

(Mu Editor or Thonny Python IDE). Not only Python Script but you can also make desktop shortcuts of any folder, directory, application and link on your Pi. I am writing a simple program of printing a text “ Hello, welcome to my Desktop!”. Save the file and run it to make sure that the program is working. 

 Creating Desktop Shortcut

Create an empty file on your Pi desktop and make sure the file name ends with .desktop.

Now open that file with Text Editor and add the following lines in it:

[Desktop Entry]= The first line of every desktop file and the section header to identify the block of key-value pairs associated with the desktop. Necessary for the desktop to recognize the file correctly.

Name = The name you want to be displayed on your desktop shortcut.

Encoding = It describes the encoding of the entries in this desktop file

Comment = Describes the application.

Icon = A file to use for the icon.

Exec = Add the program loader and after that add the path of the python script. The command that starts this application from a shell.

Type= Informs the desktop that the file is of application type. Other keys are Link and Directory.

StartUpNotify= When we set the value True, the panel and cursor notify the user that the application has started.

Terminal= you can choose whether you want to run the file in the terminal or not. But passing the value false you can just turn off the terminal. 

After adding all the information in the text editor, save the file. These lines are the instruction for your Pi desktop to recognize the application.  

Make the File executable

You need to make the file executable before making them run so first let’s make it executable by changing some commands. Open your Raspberry Pi terminal and start writing the command:

chmod +x

It changes the file to executable mode. And the command will be completed by adding the path name of the file which you want to make executable.

chmod +x  /home/pi/mu_code/code1.py

Run the Python Script Desktop Shortcut

You can see that the file name changed to the name you gave in the Text Editor. On clicking the shortcut a message box will pop with a message that you want to execute the file with the terminal or without a terminal. And now your file will run. This is how you can create a desktop shortcut of your python Script.