Start Program
==========================
The :func:`~desktop_entry_lib.__init__.DesktopEntry.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:

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

You can run the command using the `subprocess module <https://docs.python.org/3/library/subprocess.html>`_ .
You should also set the working directory to the value that you get with :func:`~desktop_entry_lib.__init__.DesktopEntry.get_working_directory`.

Here's a simple example:

.. code:: python

    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 :doc:`more complex example </examples/StartProgram>`.

--------------------------
Start in Terminal
--------------------------
You may now, that Desktop Entries can set the :attr:`~desktop_entry_lib.__init__.DesktopEntry.Terminal` Key to :code:`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 :code:`x-terminal-emulator`, which is a symlink to the default Terminal Emulator.
On other Distros you could try to read the :code:`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 :code:`-e` argument. So if you find the Terminal Emulator, you should be able to start the Program in the Emulator using this.

.. code:: python

    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 :attr:`~desktop_entry_lib.__init__.DesktopEntry.Terminal` Key is ignored. See above for a detailed explanation.

- Even if a Program supports `starting with D-Bus <https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#dbus>`_, it is still started with the Command.

- Your Desktop Environment may not know, which Desktop Entry belongs to the started Program, so Options like :attr:`~desktop_entry_lib.__init__.DesktopEntry.SingleMainWindow` or the :doc:`Actions <desktop_actions>` might be ignored.
