How to extend a .desktop file for adding new Actions?

I want to add some extra Actions to the shortcut that starts LibreOffice Writer, for quickly opening some of my documents by right clicking on the Favorite icon of Writer.

To do this, I copied the file /usr/share/applications/libreoffice-writer.desktop to my ~/.local/share/applications/ with a different name, simplified its contents, changed its Name= and Comment= lines, and added some new Actions=. (I do not want to change the system-wide original desktop file, since my additions should be done per user basis.)

The new shortcut appears under Activities and menus and I can start an instance of Writer by selecting it. However, after Writer starts, the right-click menu of its icon is still the original (system-wide) one: My extra Actions do not appear. And if I add it to Favorites, not any of my new Actions are added.

What is the correct method of adding some new Actions to a system-wide desktop file?

Note: My new desktop file is named ~/.local/share/applications/libreoffice-writer-xxx.desktop and has contents like this:

[Desktop Entry]
Version=1.0
Terminal=false
Icon=libreoffice-writer
Type=Application
Exec=libreoffice --writer %U
Name=LibreOffice Writer Shortcuts
Comment=Local copy of desktop file
StartupNotify=true
Actions=NewDocument1;doc1;doc2;

[Desktop Action doc1]
Name=Open doc1.odt
Exec=libreoffice --writer /home/xxx/Documents/doc1.odt

[Desktop Action doc2]
Name=Open doc2.odt
Exec=libreoffice --writer /home/xxx/Documents/doc2.odt

[Desktop Action NewDocument1]
Name=Start New Document
Exec=libreoffice --writer

Solution 1:

You are describing the good approach on how to edit a .desktop file in order to add custom actions. It is also good practice to work on a copy of the file in your .local/share/applications folder. This way, the changes are only in effect for yourself or other users that use that copy, and also ensures the changes will not be overwritten by an update.

Your specific issue, however, is where you are renaming your local copy. To prevent that the system wide .desktop file settings are used, make sure your local copy has the same file name as the system wide .desktop file. Only then will it fully replace for the system wide .desktop file.