2

In the latest update of Files, all .desktop files aren't executed by left-click by default (eg. all files in ~/.local/share/applications directory). They are opened in Scratch instead. I understand why this happens.

The reason is described here: https://medium.com/elementaryos/loki-updates-for-february-aa39cc526498#.r3zeyns1l

But now, I can't find any option to execute these files using the Files. There is no option like "Run application" or something like that. Of course, I can still run application using the terminal.

Am I overlooking something or it is intended as a feature?

  • 2
    That's not how .desktop files are designed to work. They are the backend of what's represented in the Slingshot and/or Plank. Are the shortcuts not showing up in SS and Plank as expected? – Pretzel Jones Mar 1 '17 at 23:26
  • 1
    There is a recent post on medium by Daniel Fore discussing this. He states the reason you cannot execute .desktop files with a click is because they've enforced that to protect against a potential exploit. You can read about it in the link in the section on the Files update. “Loki Updates for February” @DanielFore medium.com/elementaryos/loki-updates-for-february-aa39cc526498 – Pretzel Jones Mar 2 '17 at 2:53
  • 1
    @PretzelJones I have farther edited my answer to take into consideration the safety concerns implied by the recent updated in Files - namely: solution no 3. – user170 Mar 2 '17 at 12:11
  • 1
    @PretzelJones - But while I find the recent change reasonable based on the reasons mentioned, it seems odd to me that a similar change was not made for executable scripts: there is no way to avoid their execution when clicked: Ask before running script from Pantheon Files – user170 Mar 2 '17 at 12:57
  • I agree. Though I'm not versed enough in the particular exploit they are protecting against. – Pretzel Jones Mar 2 '17 at 13:34
2

As indicated in the comment by PretzelJones you don't need to run those files like that, as they can be launched from Slingshot if you put them in ~/.local/share/applications.

Even more, as explained here by the developer the change is intended to avoid file manager being tricked into executing arbitrary code: therefore, use the below solutions with caution, especially the one intended to execute the desktop file without asking by just clicking (solution no 1), and favor solution 3.


So, if you have some files in ~/.local/share/applications or other places that you must or want to run from Files for any reason, there must be different ways to do it, and the most obvious is to use other file managers to handle the .desktop files through Pantheon Files, either

  • by creating a ~/.local/share/applications/run-desktop.desktop file and make that "application" the default for .desktop files and thus executing them as before with one or double click, or
  • by creating a contract file to add a special context menu entry in Pantheon Files or, even better
  • by creating a ~/.local/share/applications/run-or-edit.desktop file (also using a zenity script), making that "application" the default for .desktop files and thus getting a pop-up window asking if you want to run or edit that file.

I have both Thunar and PCManFM installed, and they are both light enough, coming with no supplementary dependencies. (These file managers could be used directly when dealing with the desktop files, and not through Pantheon Files, but that's another matter.)

So:

sudo apt install pcmanfm

or

sudo apt install thunar

1. To run .desktop files by double click without asking - by changing the default application for that type of files (the less safe solution):

gedit ~/.local/share/applications/run-desktop.desktop

with:

[Desktop Entry]
Type=Application
Icon=system-file-manager
Name=PCManFM to Run desktop file
Categories=System;FileTools;FileManager;Utility;Core;GTK;
Exec=pcmanfm %f
Terminal=false
MimeType=application/x-desktop

Then make it executable:

sudo chmod a+x ~/.local/share/applications/run-desktop.desktop

(or maybe you could try my option here)

Then, selecting any .desktop file, right-click, 'Properties', and under 'Open with' select that new "application":

setting for running desktop files

You should consider the fact that the above is risky, as already indicated, while the solutions below are safer.

2. To add a context menu entry in Files to execute desktop files by creating a contract file:

gedit ~/.local/share/contractor/run_desktop_launcher.contract

with:

[Contractor Entry]
Name=Run the desktop file
MimeType=application/x-desktop
Exec=pcmanfm %f

and you should see the "Run" right-click custom menu:

enter image description here

(To make that context menu option show a "Run or edit" option instead of simply running the file: replace the line Exec=pcmanfm %f with Exec=bash -c '/path/to/your/scripts/location/run_or_edit_.sh %f' according to the the next solution below.)

3. To get a pop-up window asking you to chose between run or edit (safest option):

sudo apt-get install zenity

and then

gedit /path/to/your/scripts/location/run_or_edit_.sh

add this:

#!/bin/bash

zenity --question --text="What to do?" \
       --ok-label=Run \
       --cancel-label=Edit

case $? in
    0)pcmanfm "$1"
    ;;
    1)gedit $1
    ;;
esac

Make that script executable.

Then:

gedit ~/.local/share/applications/run-or-edit.desktop

with:

[Desktop Entry]
Type=Application
Name=Run or edit
Icon=gedit
Categories=Utility;TextEditor;
MimeType=application/x-desktop;
Exec=bash -c '/path/to/your/scripts/location/run_or_edit_.sh %f' 

Make that executable, then selecting any .desktop file, right-click, 'Properties', and under 'Open with' select that new "application" called 'Run or edit'.

Now when you click a .desktop file you will get this:

run or edit pop-up


Thunar can be used in the same way as PCManFM.

I find these file managers useful on the system for other purposes too, like for instance to add Thunar's bulk-renaming tool in Pantheon Files and to get pop-up options upon insertion of removable media with PCManFM daemon.

  • Thank you for your answer. I think I will join the discussion about this topic, because I think it is useful to be able to run application with its .desktop file. For example, I want to donwload Fritzing, which isn't in AppCenter. It's more useful to run it using left-click or right-click -> Run than placing .desktop file in /.local/share/applications and edit app path. It isn't user-friendly. – Pavel Vybíral Mar 2 '17 at 9:52
  • @PavelVybíral - I have added a way to run them by double click. – user170 Mar 2 '17 at 9:55
  • Thank you, I've posted comment a few seconds before you updated the answer. It is a good way, but I still think it isn't as user-friendly as it was when left-click option to run application was enabled. I think the option to simple run application via Files should be added back. – Pavel Vybíral Mar 2 '17 at 9:57
  • @PavelVybíral - I think so, but feature requests and bug reports are off-topic here. – user170 Mar 2 '17 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.