Skip to main content
improved answer with selective change
Source Link

Desktop entry (.desktop) files in /usr/share/applications would be overwritten on package upgrade. To override the file without losing changes, place a copy in ~/.local/share/applications and make your changes here.


Updated for selective, automated override of original desktop file on detecting changes

Goal: monitor for changes to desktop file and execute script to effect desired changes.

  1. Create script /usr/local/bin/update-myapp-desktop-file.sh to make desired changes to desktop file:
#!/usr/bin/env bash

sed -i 's/^NoDisplay=true/NoDisplay=false/' /usr/share/applications/MyApplication.desktop

Mark script as executable: chmod 755 /usr/local/bin/update-myapp-desktop-file.sh

  1. Create systemd service file /etc/systemd/system/myapp-desktop-file.service to run script:
[Unit] 
Description=Update MyApp desktop file

[Service]
ExecStart=/usr/local/bin/update-myapp-desktop-file.sh
  1. Create corresponding systemd path file /etc/systemd/system/myapp-desktop-file.path to monitor for changes to desktop file:
[Unit]
Description=Monitor for changes to MyApp desktop file

[Path]
PathModified=/usr/share/applications/MyApplication.desktop
Unit=myapp-desktop-file.service

[Install]
WantedBy=multi-user.target
  1. Verify, enable, and start systemd path file:
systemd-analyze verify /etc/systemd/system/myapp-desktop-file.*
systemctl enable myapp-desktop-file.path
systemctl start myapp-desktop-file.path

Desktop entry (.desktop) files in /usr/share/applications would be overwritten on package upgrade. To override the file without losing changes, place a copy in ~/.local/share/applications and make your changes here.

Desktop entry (.desktop) files in /usr/share/applications would be overwritten on package upgrade. To override the file without losing changes, place a copy in ~/.local/share/applications and make your changes here.


Updated for selective, automated override of original desktop file on detecting changes

Goal: monitor for changes to desktop file and execute script to effect desired changes.

  1. Create script /usr/local/bin/update-myapp-desktop-file.sh to make desired changes to desktop file:
#!/usr/bin/env bash

sed -i 's/^NoDisplay=true/NoDisplay=false/' /usr/share/applications/MyApplication.desktop

Mark script as executable: chmod 755 /usr/local/bin/update-myapp-desktop-file.sh

  1. Create systemd service file /etc/systemd/system/myapp-desktop-file.service to run script:
[Unit] 
Description=Update MyApp desktop file

[Service]
ExecStart=/usr/local/bin/update-myapp-desktop-file.sh
  1. Create corresponding systemd path file /etc/systemd/system/myapp-desktop-file.path to monitor for changes to desktop file:
[Unit]
Description=Monitor for changes to MyApp desktop file

[Path]
PathModified=/usr/share/applications/MyApplication.desktop
Unit=myapp-desktop-file.service

[Install]
WantedBy=multi-user.target
  1. Verify, enable, and start systemd path file:
systemd-analyze verify /etc/systemd/system/myapp-desktop-file.*
systemctl enable myapp-desktop-file.path
systemctl start myapp-desktop-file.path
Source Link

Desktop entry (.desktop) files in /usr/share/applications would be overwritten on package upgrade. To override the file without losing changes, place a copy in ~/.local/share/applications and make your changes here.