Python Nautilus script

kaer kaerbuhez at gmail.com
Mon Sep 15 23:26:18 CEST 2008


On 15 sep, 21:46, Michel Leunen <mic... at nospam.please> wrote:
>
> But in the case of Nautilus script, how to workaround this issue?
>
> --
> Michel Leunen
> http://linux.leunen.com

I don't have that issue.
This script works as expected:
---------------
#! /usr/bin/python
# -*- coding: utf8 -*-

import os, sys

#NAUTILUS_SCRIPT_SELECTED_FILE_PATHS : chemins des fichiers
sélectionnés séparés par des retours à la ligne (newline) (uniquement
pour les fichiers locaux)
#NAUTILUS_SCRIPT_SELECTED_URIS : URIs des fichiers sélectionnés
séparés par des retours à la ligne (newline)
#NAUTILUS_SCRIPT_CURRENT_URI : URI de l'emplacement actuel
#NAUTILUS_SCRIPT_WINDOW_GEOMETRY : position et taille de la fenêtre
actuelle


KEYS=("NAUTILUS_SCRIPT_SELECTED_FILE_PATHS",
"NAUTILUS_SCRIPT_SELECTED_URIS", "NAUTILUS_SCRIPT_CURRENT_URI",
"NAUTILUS_SCRIPT_WINDOW_GEOMETRY")

ft=open("/home/kaer/stupid.txt", "w")
for key_value in [(key, os.environ.get(key, 'NOT FOUND')) for key in
KEYS]:
    ft.write("env(%s): %s\n" % key_value)
file_names=sys.argv[1:]
for index, file_name in enumerate(file_names):
    ft.write("%s: [%s]\n" % (index, file_name))
    if os.path.isfile(file_name): os.rename(file_name, '%03d-%s' %
(index+1, file_name))
ft.close()
---------------
I selected 3 files (created on purpose) in Nautilus.
Those files where renamed and stupid.txt created with that content:
---------------
env(NAUTILUS_SCRIPT_SELECTED_FILE_PATHS): /home/kaer/baz
/home/kaer/bar
/home/kaer/foo

env(NAUTILUS_SCRIPT_SELECTED_URIS): file:///home/kaer/baz
file:///home/kaer/bar
file:///home/kaer/foo

env(NAUTILUS_SCRIPT_CURRENT_URI): file:///home/kaer
env(NAUTILUS_SCRIPT_WINDOW_GEOMETRY): 1280x885+0+25
0: [baz]
1: [bar]
2: [foo]
---------------
You can as well use sys.argv[1:] that will give you the list of
selected files.

Hope that helps.



More information about the Python-list mailing list