How to add submenus to context menus?

I have figured out how to make a context menu in pcmanfm-qt

in .local/share/file-manager/actions/extract.desktop

[Desktop Entry]
Name=Extract Files Here

[X-Action-Profile profile-zero]
Exec=~/Scripts/ %f

And i also found a pretty great example for conditional context menu entries

But I cannot for the life of me figure out how to make a context menu item that has a submenu, how do i do it?

Take a look here:

Press CTRL+F and type “sub” to get to the parts about sub-menus.

1 Like

what is here the menings of btw ? when i rightclick on tar package , it tells extract or extract to
…and i can make tar from right menu … on every folder

Do you mean “Extract Files Here”? It should mean extract to the current folder or a specified folder.

However, this is just the name of the menu entry. The actual name of the command is determined by the archiver you are using. The OP doesn’t specify the name of the archiver, as they are using a script that links to their actual archiver.

1 Like

It’s just my own custom script lol, it tries to smartly extract files to a subfolder based on some conditions. I should probably rename the menu entry tbh it’s confused me a couple times.

More about the script

I like it better than the lxqt-archiver based extract here function of pcmanfm-qt, both because it gives me more control and I understand how it works, and because sometimes the built in extract function doesn’t extract to subfolders and just dumps a bunch of files into the directory where the archive is located, which I practically never want (And if I would want it, I would want it only when i explicitly request it).

Here’s the script if you’re interested.


#Smartly extracts files to a single subfolder; named after archive by default, but named after the folder inside the archive if it was already arranged into a subfolder within the archive.
subfolder="$(echo $@ | cut -d '.' -f1)"
mkdir "$subfolder"
cd "$subfolder"

notify-send "extracting $(basename "$@")..."

for var in "$file"
echo filename "$var"
if [ -f "$var" ] ; then
       case "$var" in
           *.tar.bz2)   tar xvjf "$var"    ;;
           *.tar.gz)    tar xvzf "$var"    ;;
           *.bz2)       bunzip2 "$var"     ;;
           *.rar)       unrar x "$var"     ;;
           *.gz)        gunzip "$var"      ;;
           *.tar)       tar xvf "$var"     ;;
           *.tbz2)      tar xvjf "$var"    ;;
           *.tgz)       tar xvzf "$var"    ;;
           *.zip)       7za x "$var"       ;;
           *.Z)         uncompress "$var"  ;;
           *.7z)        7z x "$var"        ;;
	   	   *.lzh)		lha x "$var"		 ;;
           *)           echo "I don't know how to extract '$var'..." ;;
       echo "'$var' is not a valid file!"

#Ensure good folder structure
if [ $(ls -1q | wc -l) == 1 ]; then
	if mv -f ./* ../ ; then
		cd ../
		rm -r "$subfolder"
		mv ./*/* ./
		mv ./*/.* ./
		rm -r "$subfolder"

notify-send "$(basename "$@") has been extracted."

Anyhow I asked about this elsewhere at around the same time and got this as an answer:

So to summarize. If I want the extract files (~/.local/share/file-manager/actions/extract.desktop) action from my OP to be part of a submenu, I can do:


[Desktop Entry]

Where the extract.desktop, another-action.desktop and yet-another-action.desktop from within ~/.local/share/file-manager/actions/ would be the submenu items.

It uses the mimetypes setting from the desktop entries it refers to to determine if it shows up or not.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.