How can I write Nautilus scripts in Python?

I want to write a Nautilus script in Python. Is that possible? If it is possible, how can I do that?


Nautilus Scripts

Nautilus scripts can be written in any programming language, including python. You just need to make your python source file executable and copy it to ~/.gnome2/nautilus-scripts in Ubuntu versions prior to 14.04. For Ubuntu 14.04 and newer the directory is different: ~/.local/share/nautilus/scripts

You will also need to add #!/usr/bin/env python as the first line of the file. Note that by default #!/usr/bin/env python points to Python2. If you need Python 3 specifically, use #!/usr/bin/env python3.

Once you have done all this, the script will be accessible from the scripts sub-menu of the right click menu in Nautilus.

nautilus scripts menu

See also:https://help.ubuntu.com/community/NautilusScriptsHowto

Nautilus Extensions

Nautilus extensions have more flexibility than scripts - eg. they can be used to add an item directly to the context menu. There is are python bindings available (python-nautilus).

Visit the web page of this library and view the documentation for more information.