I would like to create a couple of nautilus actions that will only show up if a certain file is in the folder. These are location actions, a simple example of one I would like is a "Make" option that runs make in the folder, but only shows up if that folder contains a makefile. Is something like this possible?

I have tried playing with basenames but they seem to only work for selected items. I have also looked into the "Execution Environment" option on the "Environment" panel. I could probably do this by using the "Appears if the command outputs 'true'" option, but I can't figure out how to pass the folder path to that command.


I was able to solve this with a lot of playing around.

First I found that the standard variables can in fact be passed to the 'Appears if the command outputs "true"' setting on the Environment tab by using zenity to view what this was doing. The one we are interested in here is %f. Also worth noting is that the command must output "true" with no newline to its stdout, rather than simply using a zero return code to mean true.

I then tried inputing the following command:

ls '%f' | grep -q 'Makefile' && echo -n 'true'

Which should work fine but it seems that there must be a SINGLE command in that field, the piping and && won't work.

I ended up creating the following script which I marked as executable and placed in my bin directory

# testexists

ls $1 | grep -q $2 && echo -n 'true'

Then I put the following into the 'Appears if command outputs "true"' field

testexists '%f' 'Makefile'

And everything started working (e.g. my make command only shows up if the folder contains a Makefile).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.