.desktop files are not executable on centos8

Viewed 1455

I’ve created a .desktop files from a python script with centos 7 (I deploy remotely in ssh desktop files), this shortcut execute an other python script. The OS has been upgraded to centos 8.

Unfortunately, my desktop entries didn’t work anymore for users.

2 problems:

-For the User, the icon is not displayed (file is untrusted, user need to trust the file to display the icon). I try to execute : gio set myShortcup.desktop metadata::trusted yes it seems to work fine, but user has to click f5 to refresh desktop)

-When User double clic on the .desktop file, text editor with desktop entry code is opening: but for me on the remote terminal with ./myShortcut.desktop command the Application is launched). User has to right click on file and make it executable to fix the problem, and it works only in desktop folder (not directly in desktop).

Please, How I can fix these two problems remotely and in generating these shortcuts ?

Generating Code :

#!/usr/bin/env python2

import os, sys, logging
import glob
import os.path
import datetime

# DECLARATION
desktopPath         = "/home/user/Desktop/"
scriptPath          = "/home/user/Desktop/DEPLOY/"

# METHODS
def createShortcut(fileName):

        # File name
        shortcutName = fileName.replace(".raw","") + ".desktop"

        # Remove file if exists
        try:
                os.remove(desktopPath + shortcutName)
        except OSError:
                pass

        with open(desktopPath + shortcutName, "w") as shortcut:
                shortcut.write("[Desktop Entry]\n")
                shortcut.write("Name=" + fileName.replace(".raw","") +"\n")
                shortcut.write("Exec=python2 " + scriptPath +"myApp.py -f " + fileName + "\n")
                shortcut.write("Terminal=true\n")
                shortcut.write("Type=Application\n")
                shortcut.write("Icon="+ scriptPath + "icon.png\n")

        shortcut.close()

        # Add execution permission
        try:
                os.chmod(desktopPath + shortcutName, 0o777)
        except OSError:
                pass


# MAIN CODE 

def main(argv):

        # Set logging level
        logging.basicConfig(stream=sys.stderr, level=logging.INFO)

        # Loop raw files
        fileList = glob.glob('*.raw')

        for i in fileList:

                # Create shortcut on PC desktop
                fileName = i
                createShortcut(fileName)



if __name__ == "__main__":
        main(sys.argv)

Created File :

[Desktop Entry]
Name=myShortcut
Exec=python2 /home/user/Desktop/DEPLOY/myApp.py -f myShortcut.raw
Terminal=true
Type=Application
Icon=/home/user/Desktop/DEPLOY/icon.png

Thanks

1 Answers

I've tested on a centos 8.2.2004 vm with virtualbox at home, and I reproduced the issue, I couldn't execute the script, can also not do a right click "allow launching".

After some hours of investigations, to solve these issues, you need to edit chmod 777 to 775 (probably linux security... selinux? I don't know exactly why) And you also need to add the gio metadata trusted command (don't pay attention to my bad indent) :

        # Add execution permission
        try:
        os.chmod(desktopPath + shortcutName, 0o755)
        cmd="gio set "+ desktopPath+shortcutName + " \"metadata::trusted\" true"
        os.system(cmd)
        except OSError:
                pass

And after that, it worked. Test it on your machine and tell us if it solved the issue.

Related