[HOW TO] Add actions to right-click context menu

This method does not work for ZorinOS 16.2 Lite.

We can create our own custom context actions by using a tool called Actions For Nautilus. It has a decent documentation page with more information about how it works, how to install it and some popular recipes that we can later import to our configuration.

This post summarizes those steps and gives a slightly more detailed overview of how things work.

Install Actions For Nautilus

Open a new terminal and run the following commands, one at the time.

sudo apt install git make python3-nautilus python3-gi procps libjs-jquery
git clone https://github.com/bassmanitram/actions-for-nautilus.git
cd actions-for-nautilus
make install
rm -rf actions-for-nautilus

Simple as that, it's installed and we're ready to start. To uninstall it, run the same commands except the third one which should read make uninstall. Note that we won't be able to launch this program from our start menu, but it will be available when searching for it on the activites overview (by pressing the Super or Windows key).

Recipe ideas

Once installed it's up to you how you want to configure your context menu. You can launch the program and use the web interface to build your own custom configuration, which you can later export/import to share with others. The project's website has a convenient wiki with a few useful configuration examples to get you started.

To add these "recipes" as I like to call them, add the contents inside the JSON tab within the AFN. Don't forget to click "Save" on both buttons for changes to take effect, as shown in the screenshot below:

Here's a few "recipes" that you can already use in addition to the ones shown in the original project's wiki. Feel free to share your own or ask for help to create one.

Convert image files to different formats

Summary

When clicked on an image or group of selected images, this will display a menu option to convert between different image formats.
This configuration below in particular only shows webp, jpeg and png but others are possible. Refer to the imagemagick documentation for all supported formats and other possible actions.

Prerequisites

This recipe requires imagemagick to work. Install this with:

sudo apt install imagemagick

Config

{
    "type": "menu",
    "label": "Convert to...",
    "actions": [
        {
            "type": "command",
            "label": "WEBP",
            "command_line": "convert %f -format webp '%w'.webp | zenity --width 300 --progress --auto-close --pulsate --text \"Processing '%f'.webp...\"",
            "cwd": "%d",
            "use_shell": true,
            "mimetypes": [
                "image/*"
            ]
        },
        {
            "type": "command",
            "label": "JPEG",
            "command_line": "convert %f -format jpeg '%w'.jpeg | zenity --width 300 --progress --auto-close --pulsate --text \"Processing '%f'.jpeg...\"",
            "cwd": "%d",
            "use_shell": true,
            "mimetypes": [
                "image/*"
            ]
        },
        {
            "type": "command",
            "label": "PNG",
            "command_line": "convert %f -format png '%w'.png | zenity --width 300 --progress --auto-close --pulsate --text \"Processing '%f'.png...\"",
            "cwd": "%d",
            "use_shell": true,
            "mimetypes": [
                "image/*"
            ]
        }
    ]
},
Calculate total combined size

Summary

When right-clicking on a directory, it will calculate the total size of all files inside that directory and report back with a prompt.

Config

{
    "type": "command",
    "label": "Calculate Size",
    "command_line": "du -sh %d | xargs -I {} zenity --info --text={} --width 150",
    "use_shell": true,
    "filetypes": [
        "directory"
    ]
}
3 Likes

Been looking for something like this ..... will definitely check this out later as I bookmarked to read after a bit .... thanks Zen .... :+1:

1 Like

I tried this on Zorin OS 17.2 and it didn't work for me. This did though:

Go to github thread and find the "VSCodeExtension.zip" (fourth response). Download it, and then extract. Go into the folder via terminal and run "make".

Original github thread for download link