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