I want to be able to select a file, run a script with a shortcut and that script gets the path of the file I've selected (or am dragging). I've selected it in nautilus.

I know how to run the command, I just don't know how to get the location of the selected file. I am assuming it is possible, because if I drag and drop a file to terminal, it pastes the path...

What did I use this for? I have a program called synergy which is for using 1 mouse and 1 keyboard across many computers, using a local network.

You can set it up to have your screens next to each other like so:

However, (because this is the free version), I can't drag and drop files between them. So this dock is set up between the two screens, and when I drag a file I can drop it there - and it copies it to the same path on the second computer (if it exists) or to the misc folder.

  • It would be informative if you could mention how to run command at the edge. – daltonfury42 Jul 5 '15 at 20:54
  • @daltonfury42 the what? – Tim Jul 5 '15 at 20:54
  • @daltonfury42 yes, GNOME 3 – Tim Jul 5 '15 at 20:55
  • @daltonfury42 with the commands section of ccsm. – Tim Jul 5 '15 at 21:01
  • 1
    It would be really interesting to know what you did with it. Can you please add it in the question? – daltonfury42 Jul 6 '15 at 22:04

With a little reaserch, I found out what you may be looking for. This can be done using .desktop files. Let me demonstrate.

Create a file in your home diretory(as an example) with the extension .desktop with the following content:

#!/usr/bin/env xdg-open

[Desktop Entry]
Exec=bash <path-to-your-script> %u
Name=visible name here
Comment=comment here
Icon=icon path here

Replace <path-to-your-script> with path of the script you want to execute. Here %u is the path of the file which you will be dragging on the .desktop file to trigger the script. This will obviously be passed as an argument to your script.

Don't forget to make your .desktop executable as well by:

chmod u+x test.desktop

To check if it is working you can point it to this script:


echo $1 > ~/out.txt

You will see the full path of the file which you dragged onto your .desktop file stored in out.txt in you home directory.

Finally, you can set up a dock to have just this in it, so you have it at the side of the screen.


Desktop Entry Specification

Gnome Developer - Desktop Files

| improve this answer | |
  • Yeah, this works with Plank dock, I can have just that icon on it - and it can be where I want. – Tim Jul 6 '15 at 16:33
  • @Tim, good to hear. – daltonfury42 Jul 6 '15 at 16:33
  • I'll add the bounty in 4 hours – Tim Jul 6 '15 at 16:37

For those who didn't liked the dock solution can simply make use of Nautilus environment variable NAUTILUS_SCRIPT_SELECTED_FILE_PATHS or $@.Write a script, place it in the scripts folder so it will appear in context menu. The advantage is that you can select more files at once. To test it:

exit 0
| improve this answer | |

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.