[SOLVED] View the commands that run from right-click menu

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
biluluki

[SOLVED] View the commands that run from right-click menu

Post by biluluki »

When you right-click on an icon, desktop, ... a menu opens with several options (actions avaiable). How can you know which command(s) is/are executed when clicking on any of those?

Are these commands stored in some configuration file? Are they stored in some log file after running?

Thank you
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
biluluki

Re: View the commands that run from right-click menu

Post by biluluki »

Some of the options are in files inside /usr/share/caja/ui , specially in caja-directory-view-ui.xml : each name of each menuitem is related to an action. But, which command(s) are related to those actions?
User avatar
Dngrsone
Level 5
Level 5
Posts: 574
Joined: Thu Nov 29, 2012 12:18 pm

Post by Dngrsone »

It might be easier for us to help you if we knew what you are trying to do.

Are you wanting to add a command to the right-click menu, or customize a particular command?

Sent from my SPH-L720T using Tapatalk
Try politeness; people will like you for it.
biluluki

Re: View the commands that run from right-click menu

Post by biluluki »

Thanks, Dngrsone

I just want to know what command(s) is called from any option of the right-click context menu.

OK, if it makes it easier to be answered ...

... let's say I want to customize a particular option of the right-click menu.

Regards
altair4
Level 20
Level 20
Posts: 11447
Joined: Tue Feb 03, 2009 10:27 am

Re: View the commands that run from right-click menu

Post by altair4 »

Once upon a time during the golden age of linux there used to be a file ... /usr/share/nautilus/ui/someting-something.xml which allowed you to do stuff.

That's gone and instead all of these default context menu items are part of the application so unless you are a programmer and want to change the source and recompile you are out of luck.

There's an "ask ubuntu" question on this and if I can find it again I'll edit this post.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
User avatar
Dngrsone
Level 5
Level 5
Posts: 574
Joined: Thu Nov 29, 2012 12:18 pm

Post by Dngrsone »

Well, if nothing else, you should be able to add a custom menu item.

As I recall, the desktop right-click menu is dependant on the browser.

As Altair mentioned, the Gnome 2 desktop used nautilus.

For Cinnamon, it would be nemo, and KDE uses dolphin.

I think lxde uses thunar; unfortunately, I am unfamiliar with Mate, and can't tell you which browser that DE uses.

At any rate, if you research your browser, you should be able to discover ways to customize that menu.

Sent from my SPH-L720T using Tapatalk
Try politeness; people will like you for it.
biluluki

Re: View the commands that run from right-click menu

Post by biluluki »

[Thunar is used by Xfce. PCManFM is used by LXDE.]

I use Linux Mint 17 MATE. But in the preferences of the Caja file manager I see no way to customize the right-click context menu.

Any ideas?
anandrkris

Re: View the commands that run from right-click menu

Post by anandrkris »

https://github.com/NiceandGently/caja-actions Got this in Google...Not sure if it helps...
User avatar
Dngrsone
Level 5
Level 5
Posts: 574
Joined: Thu Nov 29, 2012 12:18 pm

Re: Re: View the commands that run from right-click menu

Post by Dngrsone »

biluluki wrote:[Thunar is used by Xfce. PCManFM is used by LXDE.]

I use Linux Mint 17 MATE. But in the preferences of the Caja file manager I see no way to customize the right-click context menu.

Any ideas?
Thanks for the correction.

Sent from my SPH-L720T using Tapatalk
Try politeness; people will like you for it.
biluluki

Re: View the commands that run from right-click menu

Post by biluluki »

Thanks

The source code of Caja seems to be in http://packages.linuxmint.com/pool/impo ... rig.tar.xz

I've been searching & having a look to the files inside of that compressed one but I don't get an answer. E.g. if with mate-search-tool you search for text with "safely" you see some C source code files with "Safely Remove Drive", but I don't see with which command(s) that action is achieved.
Buzzsaw
Level 6
Level 6
Posts: 1318
Joined: Sat Aug 23, 2014 12:53 pm

Re: View the commands that run from right-click menu

Post by Buzzsaw »

This might work, though it probably won't:

1. open terminal
2. kill caja
3. start caja using:

Code: Select all

strace caja
4. use the caja right-click menu
5. examine the output of strace to see what caja did.
acerimusdux
Level 5
Level 5
Posts: 633
Joined: Sat Dec 26, 2009 3:36 pm

Re: View the commands that run from right-click menu

Post by acerimusdux »

Well the simplest thing to start, if all you wanted to do was customize which applications are offered for a specific item, you can do some of that from control center, under "preferred applications"; basically which image viewer is offered if it's an image file, which browser is offered if it's a webpage, what terminal emulator is used for "open in terminal", etc.

Getting more complicated, you can really customize, add menu options, etc., if you install the packages python-caja and gir1.2-caja (the latter isn't listed as a dependecy but should be, it won't work without it). There are a few simple examples stored in /usr/share/doc/python-caja/examples, which you can play with. For example, copy the submenu.py script from there to your home directory, ~/.local/share/caja-python/extensions/ and you will see it adds new menu items to both the desktop menu, and the menu you get when you click on an item.
biluluki

Re: View the commands that run from right-click menu

Post by biluluki »

Thanks

I think that "2." should be "killall caja" instead of "kill caja". Otherwise you get "bash: kill: caja: arguments must be process or job IDs" and Caja is not killed or finished.

But with "strace caja", after many text lines, it says "+++ exited with 0 +++" and exits, so you get no output in the terminal right-clicking later.
biluluki

Re: View the commands that run from right-click menu

Post by biluluki »

Thanks, acerimusdux. What you suggest works after:

Code: Select all

killall caja
But with that I cannot know the command(s) that run when clicking on any of the default options of the right-click context menu of Caja.

Any ideas, please?
biluluki

Re: View the commands that run from right-click menu

Post by biluluki »

In http://packages.linuxmint.com/pool/upst ... nt1.tar.gz we have the source code of Thunar but I don't find inside it the commands related to the right-click menu.
acerimusdux
Level 5
Level 5
Posts: 633
Joined: Sat Dec 26, 2009 3:36 pm

Re: View the commands that run from right-click menu

Post by acerimusdux »

biluluki wrote:Thanks, acerimusdux. What you suggest works after:

Code: Select all

killall caja
But with that I cannot know the command(s) that run when clicking on any of the default options of the right-click context menu of Caja.

Any ideas, please?
Well instead of kill, you can also use the command

Code: Select all

caja - q
which causes caja itself to quit (after which the session manager will apparently restart it).

As for the specific commands run in the context menus, you may really have to dig through the source code to get that. First question though is which context menu? The desktop (create folder, create launcher, create document, organize desktop, etc.), or the one when you select a file or folder (open, cut, copy, paste, rename, move to trash, etc.)?

It looks to me that items are being put into those menus by adding them to get_background_items, get_file_items, or get_toolbar_items. But that's just the python code which uses caja-extensions. That's designed to make it easier to extend and add custom items, but not to edit the built in items. For that, you probably have to get into the C code, maybe look for any files which contain:

Code: Select all

#include "fm-actions.h"
That's where a lot of the file menu items seem to be declared, but you will have to dig into the code to see where they are implemented.
User avatar
Dngrsone
Level 5
Level 5
Posts: 574
Joined: Thu Nov 29, 2012 12:18 pm

Re: View the commands that run from right-click menu

Post by Dngrsone »

A little judicious searching of the intarwebs netted me two things; hope they may be of help for caja:

caja actions
caja scripting
Try politeness; people will like you for it.
biluluki

Re: View the commands that run from right-click menu

Post by biluluki »

Thanks!

[Here, after "killall caja" or "caja -q" Caja closes, but doesn't open automatically again -I have to do it myself if I want-]

So the key file for the subject seems to be /path/of/caja-1.8.1/src/file-manager/fm-actions.h

Inside it, for example, I find:

Code: Select all

#define FM_ACTION_EJECT_VOLUME "Eject Volume"
OK, but I find nothing else about ejecting volumes. I know to safely remove USB flash drives using terminal commands (sudo eject or umount + udisks --detach), but I don't see them in this file nor in the others of the source code.

Is FM_ACTION_EJECT_VOLUME something that can safely remove USB flash drives by itself (without any relation to any command)? Is this action related to something (library ...) non-programmers usually don't know?

I'm just learning ... Any info will be helpful ...
acerimusdux
Level 5
Level 5
Posts: 633
Joined: Sat Dec 26, 2009 3:36 pm

Re: View the commands that run from right-click menu

Post by acerimusdux »

biluluki wrote:Is FM_ACTION_EJECT_VOLUME something that can safely remove USB flash drives by itself (without any relation to any command)? Is this action related to something (library ...) non-programmers usually don't know?

I'm just learning ... Any info will be helpful ...
Well in C code, all functions and variables are declared in the header files (end in .h), but what they do is actually defined elsewhere in the code. And the way the code works, those definitions for different commands might be in different places, when they just define one they probably just add it to the already existing menu object.

A good source code browser would likely allow you to quickly find all places where FM_ACTION_EJECT_VOLUME is referenced. And maybe you could figure things out from there. Most likely you would find that the command for removing a USB drive is being pulled from some standard library of some sort, as it's likely not the sort of thing the developers of a file manager would want to reinvent. And it's possible those fuctions will be calling standard commands like eject or umount, but it's also possible they would just be using the same libraries as used by those commands.

But I have to ask, is there something specific you wanted to accomplish, or is this all just to satisfy a general curiosity about how things work? Because in many cases I think there is going to be an easier way to do things than trying to sort out C code.

Suppose you want to see what happens when you unmount that flash drive, for example. Someone above mentioned "strace", which might be one way to go about it. But you could probably also open a terminal and run "top" (which stands for table of processes), sort by cpu usage, and then unmount the drive. And you might well find that the "umount" command is being called, and would show up as a process, with it's own pid. And I believe there's also a command that will tell you what command was initially called to run a process.

Then there's the gnu accounting utilities, which will log every process run ("apt-get install acct"). Once that's running, you can use the "lastcomm" command to list the most recently run commands logged. "lastcomm| tail -50" for example would give the last 50. That would also tell you if "eject" or "mount" were called.
Locked

Return to “Other topics”