Python Nautilus script

Diez B. Roggisch deets at nospam.web.de
Mon Sep 15 15:33:12 EDT 2008


Michel Leunen schrieb:
> Hi,
> 
> I'm trying to write a python script for Nautilus.
> To get the list of files selected in the Nautilus right pane, you use 
> the $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS environment variable which is 
> normally available to the script. Actually, it works with bash scripts 
> but not with python scripts
> 
> import os
> files = os.environ['NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'].splitlines()
> 
> gives a:
> 
> File "<stdin>", line 1, in <module>
>   File "/usr/lib/python2.5/UserDict.py", line 22, in __getitem__
>     raise KeyError(key)
> KeyError: 'NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'
> 
> Fredrik Lundh explained me that all environment variables are not 
> accessible from subprocesses of an application.
> 
> So my question is how can I get the Nautilus selected files in a python 
> script?

There shouldn't be a difference between a shell-script and a 
python-script. Environment-variables are a unix-process-thing, and thus 
the rules that govern them apply to *all* processes - the shell is one 
of these, there is nothing special to it.

If the shell-script gets the variable, the python-script will as well.

Are you sure the shell gets the value? Or is it just silently ignoring a 
missing value, and the python-script isn't? According to the docs (I 
only googled the variable-name), the variable seems only to be set "only 
if local"[1], whatever that means.

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

Diez




More information about the Python-list mailing list