Lesson 12 of 19 ↓
- 1.Fedora + Distrobox + Arch + AUR Setup Guide
- 2.Enabling Hibernate on Linux
- 3.A Practical Git Workflow
- 4.Useful Linux Commands & Tips
- 5.Mirroring Your Android Screen with Scrcpy
- 6.Downloading Media with Yt-dlp
- 7.Consistent C/c++ Style with Clang-format
- 8.Auto-mounting Drives at Boot
- 9.Customizing Grub
- 10.Linux Swap Files Explained
- 11.Zram: Compressed Swap in Ram
- 12.Custom App Launch Behavior Via .desktop Files
- 13.Custom Mime Icons in Gnome
- 14.Fixing Missing Dock Icons (startupwmclass)
- 15.Installing Questasim for Hdl Simulation
- 16.Building Python 2 From Source
- 17.Auto-Starting WhatsApp and Telegram (Minimized or Tray)
- 18.Custom Neovim Configuration Guide
- 19.Running Windows Applications on Linux Seamlessly with WinBoat (Docker)
1 min read
Custom App Launch Behavior Via .desktop Files
Changing how a Linux application launches — forcing dark mode, injecting an environment variable, adding a HiDPI scale flag — doesn't require patching the app itself. Every launchable app on the system has a .desktop file describing how to run it, and it's possible to override that safely without touching the original.
Why Not Edit the System File Directly
Editing /usr/share/applications/*.desktop directly is a bad idea for two reasons: system updates will silently overwrite it, and the change affects every user on the machine. The fix is to copy the file into ~/.local/share/applications/ — the system always prefers a user-local .desktop file over the system-wide one with the same name.
Create the Local Applications Directory
mkdir -p ~/.local/share/applicationsCopy the Original .desktop File
Example for GParted:
cp /usr/share/applications/gparted.desktop ~/.local/share/applications/Edit the exec= Line
Open the copy:
nvim ~/.local/share/applications/gparted.desktopThe Exec= line is the actual command the system runs to launch the app. To force dark mode, prefix it with an environment variable via env:
# Before
Exec=/usr/sbin/gparted %f
# After — force a dark theme
Exec=env GTK_THEME=Adwaita:dark /usr/sbin/gparted %fAny other program-specific flag can be added the same way — e.g. --force-device-scale-factor=1.5 for HiDPI scaling.
Update the Desktop Database
update-desktop-database ~/.local/share/applicationsThis makes the system pick up the local override immediately.
Adjusting Privilege Escalation
For tools like GParted that need root, make sure Exec= routes through the correct wrapper for the desktop environment — pkexec is the standard PolicyKit wrapper:
Exec=pkexec /usr/sbin/gpartedOnce saved and the database updated, the next launch from the application menu uses the new behavior — dark mode, custom flags, or the adjusted privilege escalation — without ever touching the original system file.
Comments
Loading the discussion…