So for a course I'm taking in operating systems I've chosen to integrate a custom ftp-like program into the right click menu (written in C) and I've been having problems with trying to get the scripts I've made appear and work the way I want them to.

The goal is to make it appear as integrated into the OS as possible. I've found a topic on how to add an action in the regular right click menu but I've been having trouble getting my nautilus scripts to work correctly.

The problem arises that even with the script in the nautilus script folders, running it in a nautilus action doesn't fill in the file-select variables (NAUTILUS_SCRIPT_SELECTED_FILE_PATHS) that the script needs to run my program. However running them via scripts menu does. I'd like to know if it's possible for this to work?

This appears when no files have been selected since this will start my program to receive the files. I need to get this to be able get the folder I've right clicked within if possible:

Receiving button, located on the right click menu

This appears when some files are selected, I need to be able to get the list of ones selected so that my program knows which files to send:

Send button, located on the right click menu

What I have to do currently is use the scripts menu This is undesirable because the scripts menu only appears when an item is selected:

What I have to do currently, use the scripts menu

Is what I want to do possible?

Additional information: The program to send/recieve them is a socket server I've written, I am aware I could probably do it much easier with simple bash FTP but I don't my prof would be impressed by a 4 line solution on a term project.

I'm writing the scripts in bash.

Here is an example of the bash code:


echo Hello World!
IP=$(zenity --entry --text "What is the IP you want?" --entry-text "")
PORT=$(zenity --entry --text "What is the PORT you want?" --entry-text "3000")
                zenity --info --text $file
        /home/admin/fileSending/clientRecieve $IP $PORT "$file"

echo $IP

I figured out the answer, in short, you need to use the parameters to give your variables. The parameter %b hands in the file name as a command line argument which can be accessed via the "$1" for the first argument. in the case of %B it will give you all the files as separate arguments, so you will need "$1" "$2" etc...

You can also use $PWD to get the current working directory. HOWEVER, there are some important things to note about this, as the current working directory is not always what you might think it is. When you have selected a file in the folder say, /home/admin/myStuff/test.txt the script's working directory will be /home/admin/myStuff. You can therefore use "$PWD/$1" to get current working directory + / + the selected file. Code is as follows

#Author: Thomas Migus, created on March 20th 2018
#this is a script that runs the client that will send the file.
IP=$(zenity --entry --text "What is the IP you want?" --entry-text "")
PORT=$(zenity --entry --text "What is the IP you want?" --entry-text "3000")
/home/admin/fileSending/clientSend $IP $PORT $FILE
zenity --info --text "File sent"

When you have not selected a folder, the working director changes. Lets say you right click on empty space inside /home/admin/myStuff the working directory will be /home/admin NOT /home/admin/myStuff

In order to select the working directory, you can use %b to get what directory you're actually in. The code is as follows:

#Author: Thomas Migus, created on March 20th 2018
# This is a script which runs the server
PORT=$(zenity --entry --text "What is the port number?" --entry-text "3000")
/home/admin/fileSending/serverRecieve $PORT $OUTPUT
zenity --info --text "File recieved"

you can test it yourself with this small script

zenity --info --text "$1"
zenity --info --text "$PWD"

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.