1

I have created a .desktop file for a program I use frequently. When I left click the .desktop file, it runs the program. I would like to have an "exit/close" option when I right click the file.

How would I go about doing this?

1 Answer 1

0

There are various features examples, right-click filemenu, on your disk.

You can find them under /usr/share/applications

Looking in the file /usr/share/applications/org.gnome.Nautilus.desktop

...
Actions=new-window;

[Desktop Action new-window]
Name=New Window
# This is how you add comments
#Icon={path}
Exec=nautilus --window-window
...

Above is truncated to only show the portions you are interested in working with.

The Actions= portion of the example is the available options in the right-click menu. So to add an additional action, or to create a new one, you need to add the Actions= section in the global options (top section).

Add your new action (ideally, keep the name simple, it is not what is seen in the menu), and it is like every other list in the file semicolon ";" separated. And by default you terminate even a list of a single item with a semicolon ";".

After adding your action you define typically at the bottom of the configuration file. You use brackets "[]" and two keywords to create right-click menu items.

For example, if we wanted to add a remote server to our nautilus right-click menu. We would modify Actions=new-window; to Actions=new-window;remote-server;.

After we do that we then define our action, using the keyword Desktop, then the keyword Action, and followed by the action name (use lowercase lettering and dashes for spaces, to be consistent with the rest of the files).

[Desktop Action remote-server]
Name=Cloud Space

Then we define things, like Name= is important because it is what we will see when we use the right-click menu. So in the above example Cloud Space would be the menu option.

Typically we would then use the Exec= keyword to do an action, but this is just one way of using Actions, they do not require Exec=. In our example, it would be likely

Actions=new-window;remote-server;

[Desktop Action remote-server]
Name=Cloud Space
Exec=ssh -Y cloudserver.your.tld nautilus

The results of our changes would introduce a new right-click menu item below "New Window" called "Cloud Space", and selecting it would ssh to the server we specified, and do X over SSH and open nautilus on the remote server and you will see the contents of the remote disk.

To know what options are available, its best to refer to the Desktop file specification/documentation.

Some people report it does not work with their custom actions until they add the option DBusActivatable=false to the general settings, like

[Desktop Entry]
Name=Terminal
...
DBusActivatable=false

[Desktop Action new-window]
...

Hope that works for you, this answer was tested on Ubuntu, but the desktop specification is quite generic, so the above should work for other linux distributions without issues.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .