Reputation: 1581
I want to get file paths of the files that are selected. I have being try this for the entire day now with no luck.
For example by clicking on the script "filename.py", I would like to get that path of the highlighted directory.
Upvotes: 2
Views: 1467
Reputation: 251136
Looking at the documentation of Nautilus scripts you can get the paths to selected files using the environment variable NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
. In Python you can get its value using os.environ
and then later you can use os.path
's functions to do operations on the paths:
import os
paths = os.environ['NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'].splitlines()
for p in paths:
if os.path.isdir(p):
print p
Upvotes: 7