I am trying to set "Allow launching" on a newly created .desktop file via a shell script. Please note that the shell script is run by
sudo
. Below is a sample script:
#!/bin/bash
# Ensure the script is run with sudo
if [ "$EUID" -ne 0 ]; then
echo "Please run as root or with sudo."
exit 1
fi
ORIGINAL_USER="${SUDO_USER}"
USER_HOME=$(eval echo ~"$ORIGINAL_USER")
DESKTOP_FILE="$USER_HOME/Desktop/test.desktop" # For testing
cp /usr/share/applications/firefox.desktop "$DESKTOP_FILE" # for testing
chown "$ORIGINAL_USER":"$ORIGINAL_USER" "$DESKTOP_FILE"
chmod a+x "$DESKTOP_FILE"
sudo -u "$ORIGINAL_USER" -g "$ORIGINAL_USER" dbus-launch gio set "$DESKTOP_FILE" metadata::trusted true
I found similar questions, such as 1 , 2 but none of them worked for this case. I also tried desktop-file-install to install on user's dekstop, but it did not work as well. BTW, I am using Ubuntu 20.04 LTS.
Asked by ravi
(143 rep)
Oct 16, 2024, 03:59 PM