I would like to write a nautilus script using python3.6 that will extract the name of a file from nautilus when the file is clicked on by the mouse pointer. Which python module can I use, or how do I write such a script from scratch?
For this script to be executable, I will make the script to start with:
#!/usr/bin/env python3
Beyond that, I will need advice on how to do what I want.
Step 1: I created the python script as shown below and saved it in folder ~/.local/share/nautilus/script
with a filename (here I called myscript.py
):
#!/usr/bin/env python3
from pathlib import Path
from os import environ
a = Path('/home/user/tmp/name.txt')
paths = environ['NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'].splitlines()
for p in paths:
a.write_text(p)
Step 2: I had to make the myscript.py
executable with this terminal command:
$ chmod +x ~/.local/share/nautilus/scripts/myscript.py