Skip to content

Instantly share code, notes, and snippets.

@nathakits
Last active Mar 10, 2021
Embed
What would you like to do?
Creating a `.desktop` file in Ubuntu that launches a Python script

Creating a .desktop file in Ubuntu that launches a Python script

Here we will make two .desktop files that will launch Pupil Capture and Pupil Player.

Steps

  1. Right click on your desktop and create a new empty document.
  2. Set the document file type by Renaming the document that ends with .desktop
  3. Drag the document into a text editor and edit the document with the example code below

Note: Change the X-Icon-Path to the icon you want to use and Execpath to where Pupil Capturemain.py` is located on your machine (see example pupil.desktop for reference)

[Desktop Entry]
Name=Pupil Capture
Version=v0.8.5
Icon=pupil-capture
X-Icon-Path=/path/to/icon/file/
Exec=python /path/to/py/file/main.py
Terminal=false
Type=Application

Option - you can use Terminal=true to launch the terminal if desired.

In the terminal set the permissions of the desktop file to be executable by typing this: chmod u+x path/to/py/file/main.py

Right click on the new empty document and in the Permissions tab, set the execute to allow executing file as program.

[Desktop Entry]
Name=Pupil Capture
Version=v0.8.5
Icon=pupil-capture
X-Icon-Path=/home/pupil-labs/Documents/Repo/pupil/deployment/deploy_capture
Exec=python /home/pupil-labs/Documents/Repo/pupil/pupil_src/capture/main.py
Terminal=false
Type=Application
[Desktop Entry]
Name=Pupil Player
Version=v0.8.5
Icon=pupil-player
X-Icon-Path=/home/pupil-labs/Documents/Repo/pupil/deployment/deploy_player
Exec=python /home/pupil-labs/Documents/Repo/pupil/pupil_src/player/main.py
Terminal=false
Type=Application
@BramBorg

This comment has been minimized.

Copy link

@BramBorg BramBorg commented Aug 20, 2019

Nice! Thanks! Sooo.... what if I have a python script that needs parameters when executed? Is it possible to click an icon on the desktop, have it ask for the desired parameter and then execute the full command in a terminal window?

@CaptStephan

This comment has been minimized.

Copy link

@CaptStephan CaptStephan commented Mar 16, 2020

@BramBorg, not sure if you got an answer to this, but I think it would be better to have the Python code ask for the parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment