0

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

1 Answers1

2

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

Daniel T
  • 4,594
  • Hello Daniel, thanks for your answer, could you clarify a little bit better the 'script interact'? as I thought that kactivitymanagerd was a file but it is a folder in $HOME/.local/share thanks in advance – otaolafr Feb 09 '24 at 12:15
  • 1
    @otaolafr The 'script interact' doesn't mean much. It's just a random sentence I used for the introduction. I changed it to "have the script talk to the service". kactivitymanagerd is indeed an executable file at /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