Start Program

The get_command() function returns the command to start a program. It takes 2 arguments, which you can use to specify what this program should open:

  1. A list of local paths. The paths should be absolute. Every path is also treated as a file:// URL.

  2. A list of URLs. Every file:// URL is also treated as local path.

You can run the command using the subprocess module . You should also set the working directory to the value that you get with get_working_directory().

Here's a simple example:

entry = desktop_entry_lib.DesktopEntry.from_file("my_app.desktop")
command = entry.get_command()
subprocess.run(command, cwd=entry.get_working_directory())

You can also take a look at the more complex example.

Start in Terminal

You may now, that Desktop Entries can set the Terminal Key to True, to indicate, that the Program should be started in a Terminal. Unfortunately there is no Way to get the default Terminal Emulator that works on all Distros and all Desktop Environments, so this is not supported by desktop-entry-lib.

On Debian based Distros, you could use x-terminal-emulator, which is a symlink to the default Terminal Emulator. On other Distros you could try to read the XDG_CURRENT_DESKTOP Environment variable to get the current Desktop Environment and launch the default Terminal Emulator e.g. Konsole on KDE. This does of course not work for every DE out there. If you use desktop-entry-lib just for personal scripts, this won't be a problem, since you should know which terminal EMulator you are using on your PC.

You can launch a given command on the most terminal Emulators using the -e argument. So if you find the Terminal Emulator, you should be able to start the Program in the Emulator using this.

subprocess.run(["your-terminal-emulator", "-e", entry.get-command()] cwd=entry.get_working_directory())

Drawbacks

Starting Programs with desktop-entry-lib works, but has a few drawbacks compared to launching it with you Desktop Environment:

  • The Terminal Key is ignored. See above for a detailed explanation.

  • Even if a Program supports starting with D-Bus, it is still started with the Command.

  • Your Desktop Environment may not know, which Desktop Entry belongs to the started Program, so Options like SingleMainWindow or the Actions might be ignored.