add app to favorites from command line KDE

I have created a .desktop for some applications in KDE inside .local/share/applications, I would like to know if it is possible to add them to ‘favorites’ in the application launcher from the terminal, as I create the .desktop from a script, similar to this question Add app to favorites from command line but for KDE

thanks in advance

Asked By: otaolafr

||

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
Answered By: Daniel T
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.