นี่คือสคริปต์หอยโข่งที่ฉันใช้เพื่อเปิดหน้าต่างผู้ดูแลระบบ (root) Nautilus:
#!/bin/bash
# This Nautilus script opens the current nautilus window in admin mode.
# Requires: perl, liburi-perl
ERROR_NEED_PERL="This script requires the liburi-perl package. Install it and try again."
GKSUDO_MESSAGE="Enter your password to open an admin window on: "
ERROR_BROKEN_LINK="Broken link."
## Check for liburi-perl (and hence perl)
let PERLOK=$(dpkg-query -W --showformat='${Status}\n' liburi-perl|grep "install ok installed")
if [ "" == "$PERLOK" ]; then
zenity --error --text "$ERROR_NEED_PERL"
exit 1
fi
let LEN_NSSFP=${#NAUTILUS_SCRIPT_SELECTED_FILE_PATHS}-1
[ $LEN_NSSFP -lt 0 ] && let LEN_NSSFP=0
let LEN_NSSU=${#NAUTILUS_SCRIPT_SELECTED_URIS}-1
[ $LEN_NSSU -lt 0 ] && let LEN_NSSU=0
## if clicking happens on the Desktop (or a file or folder on it),
## $1 will be a path (i.e. with "/" in it); otherwise (in a folder
## window) $1 will be just a file or folder name (without path).
## Note that selecting the home desktop namespace extension yields
## a $# of zero but NAUTILUS_SCRIPT_SELECTED_FILE_PATHS pointing to the
## target (in the computer (computer:///) and trash (trash:///) desktop
## namespace extension cases, ...PATHS is empty).
## Initially, we stripped the file:// prefix from NAUTILUS...CURRENT_URI,
## yielding the full path, and then retrofit spaces, like this:
#OBJECT="`echo -n $NAUTILUS_SCRIPT_CURRENT_URI | cut -d'/' -f3- | sed 's/%20/ /g'`"
## However, this fails if any special characters other than spaces are in the path,
## such as accented letters, etc. We need to convert not just spaces, but any
## UTF-8 embedded in there...The URI<->path conversion requires perl (and liburi-perl):
OBJECT=$( echo "$NAUTILUS_SCRIPT_CURRENT_URI" | perl -MURI -le 'print URI->new(<>)->dir' )
## ->file is to be used for file URIs instead of ->dir, which is for directory URIs
CONTEXT="$OBJECT"
## Add the selection to the path, if defined and unique
if [ $# -eq 1 ] ; then
## If a single Desktop object, override
if echo $1 | grep -q "/" ; then ## Desktop (or object on desktop)
OBJECT="$1"
CONTEXT=""
else ## $1 is a simple file or folder name, without a path
## The container could be root (/)
OBJECT="${OBJECT%/}/$1"
fi
# elif [ $# -eq 0 -a -n "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ] ; then
elif [ $# -eq 0 ] ; then
## desktop name space extension selected?
if [ -n "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ] ; then ## Home
OBJECT="${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS:0:LEN_NSSFP}"
elif [ -n "$NAUTILUS_SCRIPT_SELECTED_URIS" ] ; then ## Computer, Trash
## These typically map to root (/)
# OBJECT="`echo ${NAUTILUS_SCRIPT_SELECTED_URIS:0:LEN_NSSU} | cut -d'/' -f3- | sed 's/%20/ /g'`"
OBJECT="${NAUTILUS_SCRIPT_SELECTED_URIS:0:LEN_NSSU}"
OBJECT=$( echo "$OBJECT" | perl -MURI -le 'print URI->new(<>)->dir' )
fi
CONTEXT=""
fi
## Note that a desktop shortcut (.desktop file) does not trip -h
if [ -h "$OBJECT" ] ; then ## symbolic link
## readlink has no "follow symlinks as far as they exist" option
OBJECT=`readlink -e "$OBJECT"`
if [ -z "$OBJECT" ] ; then
zenity --error --text "$ERROR_BROKEN_LINK"
exit 1
fi
fi
# zenity --info --text "\$OBJECT is « $OBJECT »"
if [ -f "$OBJECT" ] ; then
## Regular file
DIR=`dirname "$OBJECT"`
else
## Directory (or no object)
DIR="$OBJECT"
fi
## If DIR is empty, gnome-open opens in the default (home) directory (i.e. "~") anyway
#if [ -z "$DIR" ] ; then
# DIR=~
#fi
## At this point, the test [ ! "$CONTEXT" = "$DIR" ] serves to indicate
## that the target directory is not matched to the one the script was
## invoked from (if any).
gksudo --message "$GKSUDO_MESSAGE$DIR" gnome-open "$DIR"
exit $?