The favorites are stored by kactivitymanagerd
service. We can have the script talk to the service:
# <Have your script create the .desktop file>
DESKTOP_FILE_NAME=org.kde.dolphin.desktop # Specify the name of the file
Add to application launcher favorites
if pgrep -cfU $UID '^/usr/lib/x86_64-linux-gnu/libexec/kactivitymanagerd$' > /dev/null; then
The service is running so ask it to add the new favorite
in the same way plasmashell would ask it to.
dbus-send --type=method_call --dest=org.kde.ActivityManager /ActivityManager/Resources/Linking org.kde.ActivityManager.ResourcesLinking.LinkResourceToActivity string:org.kde.plasma.favorites.applications string:applications:"$DESKTOP_FILE_NAME" string::any
Refresh the display
kquitapp5 plasmashell &> /dev/null
kstart5 plasmashell &> /dev/null
else
The service is not running, so modify the favorites database.
echo "INSERT INTO ResourceLink(usedActivity,initiatingAgent,targettedResource) VALUES (':global','org.kde.plasma.favorites.applications','applications:$DESKTOP_FILE_NAME');" | sqlite3 ~/.local/share/kactivitymanagerd/resources/database
fi
/usr/lib/x86_64-linux-gnu/libexec/kactivitymanagerd
but it *stores its data* in the folder at~/.local/share/kactivitymanagerd
. It's just like how konsole is an executable file at/usr/bin/konsole
but stores its files in the folder at~/.local/share/konsole
– Daniel T Feb 09 '24 at 16:54