个人工具

“UbuntuHelp:NautilusScriptsHowto”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
第17行: 第17行:
 
All of your scripts are stored in the Nautilus-scripts folder - so to add a new script, simply place it there. You can find the Nautilus-scripts folder here :
 
All of your scripts are stored in the Nautilus-scripts folder - so to add a new script, simply place it there. You can find the Nautilus-scripts folder here :
 
<pre><nowiki>
 
<pre><nowiki>
~/.gnome2/nautilus-scripts
+
    ~/.gnome2/nautilus-scripts
 
</nowiki></pre>
 
</nowiki></pre>
 
[[Top Back to top]]
 
[[Top Back to top]]
第57行: 第57行:
 
This one is really useful. How many times have you needed to find a file and then send it? And to be honest, from Evolution or mozilla-thunderbird this is not that simple. It is much easier to use Nautilus to find your file and then send it from there.
 
This one is really useful. How many times have you needed to find a file and then send it? And to be honest, from Evolution or mozilla-thunderbird this is not that simple. It is much easier to use Nautilus to find your file and then send it from there.
 
<pre><nowiki>
 
<pre><nowiki>
#!/usr/bin/perl -w
+
    #!/usr/bin/perl -w
# By John Russell
+
    # By John Russell
# This script sends the selected file(s) with your email client.
+
 
use strict;
+
    # This script sends the selected file(s) with your email client.
my $MAILTO_URL="mailto:?";
+
 
my @files = split("\n", $ENV{NAUTILUS_SCRIPT_SELECTED_FILE_PATHS});
+
    use strict;
my $count = 0;
+
 
foreach my $file (@files)
+
    my $MAILTO_URL="mailto:?";
{
+
    my @files = split("\n", $ENV{NAUTILUS_SCRIPT_SELECTED_FILE_PATHS});
if ( ! -f $file && ! -l $file )
+
    my $count = 0;
{
+
    foreach my $file (@files)
my @dialog = ("gdialog","--title","Error","--msgbox", "\nError: Can not send $file.    \n\n    Only regular files can be mailed.    ","200", "300");
+
    {
system (@dialog);
+
        if ( ! -f $file && ! -l $file )
}
+
        {
else
+
            my @dialog = ("gdialog","--title","Error","--msgbox", "\nError: Can not send $file.    \n\n    Only regular files can be mailed.    ","200", "300");
{
+
            system (@dialog);
  $MAILTO_URL = $MAILTO_URL . "attach=" . $file . "&";
+
    }
shift;
+
    else
    $count += 1;
+
    {
}
+
      $MAILTO_URL = $MAILTO_URL . "attach=" . $file . "&";
}
+
              shift;
if ($count > 0)
+
        $count += 1;
{
+
    }
my @command = ("gnome-open", $MAILTO_URL);
+
    }
system(@command);
+
 
}
+
 
 +
    if ($count > 0)
 +
    {
 +
        my @command = ("gnome-open", $MAILTO_URL);
 +
        system(@command);
 +
    }
 
</nowiki></pre>
 
</nowiki></pre>
 
Added by Darrell: I found that the mailto: syntax in the above does not work with mozilla-thunderbird. I have created the following amended version which seems to work with Thunderbird:
 
Added by Darrell: I found that the mailto: syntax in the above does not work with mozilla-thunderbird. I have created the following amended version which seems to work with Thunderbird:
 
<pre><nowiki>
 
<pre><nowiki>
#!/usr/bin/perl -w
+
    #!/usr/bin/perl -w
# By John Russell
+
    # By John Russell
# and hacked to work with thunderbird by Darrell
+
    # and hacked to work with thunderbird by Darrell
# This script sends the selected file(s) with mozilla-thunderbird.
+
 
use strict;
+
    # This script sends the selected file(s) with mozilla-thunderbird.
my $attach_string="\"attachment='";
+
 
my @files = split("\n", $ENV{NAUTILUS_SCRIPT_SELECTED_FILE_PATHS});
+
    use strict;
my $count = 0;
+
 
foreach my $file (@files)
+
    my $attach_string="\"attachment='";
{
+
    my @files = split("\n", $ENV{NAUTILUS_SCRIPT_SELECTED_FILE_PATHS});
if ( ! -f $file && ! -l $file )
+
    my $count = 0;
{
+
    foreach my $file (@files)
my @dialog = ("gdialog","--title","Error","--msgbox", "\nError: Can not send $file. \n\n    Only regular files can be mailed.    ","200", "300");
+
    {
system (@dialog);
+
        if ( ! -f $file && ! -l $file )
}
+
        {
else
+
            my @dialog = ("gdialog","--title","Error","--msgbox", "\nError: Can not send $file. \n\n    Only regular files can be mailed.    ","200", "300");
{
+
            system (@dialog);
$attach_string = $attach_string . "file://" . $file . ",";
+
        }
shift;
+
        else
$count += 1;
+
        {
}
+
          $attach_string = $attach_string . "file://" . $file . ",";
}
+
              shift;
if ($count > 0)
+
            $count += 1;
{
+
        }
$attach_string = $attach_string . "'\"";
+
    }
# replace spaces with '%20' as demanded by mozilla/thunderbird     
+
 
$attach_string =~ s/\s/%20/g;
+
 
# invoke shell script to call thunderbird differently depending on whether it's running already or not
+
    if ($count > 0)
my $command = ("~/scripts/thunderbird-email-attachments " . $attach_string);
+
    {
system($command);
+
        $attach_string = $attach_string . "'\"";
}
+
    # replace spaces with '%20' as demanded by mozilla/thunderbird     
 +
        $attach_string =~ s/\s/%20/g;
 +
    # invoke shell script to call thunderbird differently depending on whether it's running already or not
 +
        my $command = ("~/scripts/thunderbird-email-attachments " . $attach_string);
 +
        system($command);
 +
    }
 
</nowiki></pre>
 
</nowiki></pre>
 
You will see there is also a shell script which is required, (~/scripts/thunderbird-email-attachments in my example above, don't put it in the nautilus-scripts directory, otherwise it will show up in the context menu):
 
You will see there is also a shell script which is required, (~/scripts/thunderbird-email-attachments in my example above, don't put it in the nautilus-scripts directory, otherwise it will show up in the context menu):
 
<pre><nowiki>
 
<pre><nowiki>
#!/bin/sh
+
    #!/bin/sh
# if thunderbird is already running open a compose window in the running instance
+
 
 +
    # if thunderbird is already running open a compose window in the running instance
 +
 
 
    if `ps xc | grep -q mozilla-thunder`; then  
 
    if `ps xc | grep -q mozilla-thunder`; then  
 
    exec mozilla-thunderbird -a Mozilla-Thunderbird -remote        "xfeDoCommand(ComposeMessage,$1)"
 
    exec mozilla-thunderbird -a Mozilla-Thunderbird -remote        "xfeDoCommand(ComposeMessage,$1)"
# else start a new instance with the compose window only
+
 
 +
    # else start a new instance with the compose window only
 +
 
 
    else
 
    else
 
    exec mozilla-thunderbird -compose $1  
 
    exec mozilla-thunderbird -compose $1  
第133行: 第147行:
 
Mount an ISO image, from Nautilus. Note from carney1979 - this script will be updated to work with filenames containing spaces soon.
 
Mount an ISO image, from Nautilus. Note from carney1979 - this script will be updated to work with filenames containing spaces soon.
 
<pre><nowiki>
 
<pre><nowiki>
#!/bin/bash
+
    #!/bin/bash
#
+
    #
#By modprobing loop it makes sure that the module is loaded and ready for  
+
    #By modprobing loop it makes sure that the module is loaded and ready for  
#use.  If it is already loaded then nothing will happen.
+
    #use.  If it is already loaded then nothing will happen.
modprobe loop
+
    modprobe loop
for I in `echo $*`
+
    for I in `echo $*`
do
+
    do
foo=`gksudo -u root -k -m "enter your password for root terminal access" /bin/echo "got r00t?"`
+
      foo=`gksudo -u root -k -m "enter your password for root terminal access" /bin/echo "got r00t?"`
sudo mount -o loop -t iso9660 $I /media/iso
+
    sudo mount -o loop -t iso9660 $I /media/iso
done
+
      done
done
+
    done
exit0
+
    exit0
 
</nowiki></pre>
 
</nowiki></pre>
 
=== Unmount ISO ===
 
=== Unmount ISO ===
第150行: 第164行:
 
Unmount an iso image, from nautilus. Note from carney1979 - this script will be updated to work with filenames containing spaces soon.
 
Unmount an iso image, from nautilus. Note from carney1979 - this script will be updated to work with filenames containing spaces soon.
 
<pre><nowiki>
 
<pre><nowiki>
#!/bin/bash
+
    #!/bin/bash
#
+
    #
for I in `echo $*`
+
    for I in `echo $*`
do
+
    do
foo=`gksudo -u root -k -m "enter your password for root terminal access" /bin/echo "got r00t?"`
+
      foo=`gksudo -u root -k -m "enter your password for root terminal access" /bin/echo "got r00t?"`
sudo umount $I
+
    sudo umount $I
done
+
      done
done
+
    done
exit0
+
    exit0
 
</nowiki></pre>
 
</nowiki></pre>
 
=== Set file read-only ===
 
=== Set file read-only ===
第164行: 第178行:
 
Change file-permission to read-only.
 
Change file-permission to read-only.
 
<pre><nowiki>
 
<pre><nowiki>
#!/bin/bash
+
    #!/bin/bash
chmod ugo-wx $*
+
 
 +
    chmod ugo-wx $*
 
</nowiki></pre>
 
</nowiki></pre>
 
=== Edit file with gedit with root-privileges ===
 
=== Edit file with gedit with root-privileges ===
第171行: 第186行:
 
Note from carney1979 - this script will be updated to work with filenames containing spaces soon.
 
Note from carney1979 - this script will be updated to work with filenames containing spaces soon.
 
<pre><nowiki>
 
<pre><nowiki>
#!/bin/bash
+
    #!/bin/bash
#
+
    #
for I in `echo $*`
+
    for I in `echo $*`
do
+
    do
foo=`gksudo -u root -k -m "enter your password for root terminal access" /bin/echo "got r00t?"`
+
      foo=`gksudo -u root -k -m "enter your password for root terminal access" /bin/echo "got r00t?"`
sudo gedit $I
+
    sudo gedit $I
done
+
      done
done
+
    done
exit0
+
    exit0
 
</nowiki></pre>
 
</nowiki></pre>
 
=== Open Nautilus with root-privileges here ===
 
=== Open Nautilus with root-privileges here ===
 
[[Top Back to top]]
 
[[Top Back to top]]
 
<pre><nowiki>
 
<pre><nowiki>
#!/bin/bash
+
    #!/bin/bash
# root-nautilus-here
+
    # root-nautilus-here
# opens a root-enabled instance of a nautilus window in selected location
+
    # opens a root-enabled instance of a nautilus window in selected location
# requires sudo privileges and gksudo, which may involve security risks.
+
    # requires sudo privileges and gksudo, which may involve security risks.
#Install in your ~/Nautilus/scripts directory.
+
    #Install in your ~/Nautilus/scripts directory.
#
+
    #
# Placed in the public domain by Shane T. Mueller 2001
+
    # Placed in the public domain by Shane T. Mueller 2001
# Fixes provided by Doug Nordwall
+
    # Fixes provided by Doug Nordwall
#
+
    #
# 2004.04.18 -- [email protected] - Added gksudo usage to provide popup
+
    # 2004.04.18 -- [email protected] - Added gksudo usage to provide popup
#              password window if sudo has expired.  Line only echos got
+
    #              password window if sudo has expired.  Line only echos got
#              root to std output.  But gksudo updates your sudo access
+
    #              root to std output.  But gksudo updates your sudo access
#              privs, so running nautilus with sudo will succeed
+
    #              privs, so running nautilus with sudo will succeed
#              without asking for a password.
+
    #              without asking for a password.
foo=`gksudo -u root -k -m "enter your password for nautilus root access" /bin/echo "got r00t?"`
+
   
sudo nautilus --no-desktop $NAUTILUS_SCRIPT_CURRENT_URI
+
   
 +
    foo=`gksudo -u root -k -m "enter your password for nautilus root access" /bin/echo "got r00t?"`
 +
    sudo nautilus --no-desktop $NAUTILUS_SCRIPT_CURRENT_URI
 
</nowiki></pre>
 
</nowiki></pre>
 
=== Run file with root privileges ===
 
=== Run file with root privileges ===
第205行: 第222行:
 
Note from carney1979 - this script will be updated to work with filenames containing spaces soon.
 
Note from carney1979 - this script will be updated to work with filenames containing spaces soon.
 
<pre><nowiki>
 
<pre><nowiki>
#!/bin/bash
+
    #!/bin/bash
#
+
    #
for I in `echo $*`
+
    for I in `echo $*`
do
+
    do
/usr/bin/gksudo $I
+
      /usr/bin/gksudo $I
done
+
      done
done
+
    done
exit0
+
    exit0
 
</nowiki></pre>
 
</nowiki></pre>
 
=== Open search window here ===
 
=== Open search window here ===
 
[[Top Back to top]]
 
[[Top Back to top]]
 
<pre><nowiki>
 
<pre><nowiki>
#!/bin/sh
+
    #!/bin/sh
# From Johnathan Bailes
+
    # From Johnathan Bailes
# This script opens a gnome-search-tool in the directory you select.
+
    # This script opens a gnome-search-tool in the directory you select.
#
+
    #
# Distributed under the terms of GNU GPL version 2 or later
+
    # Distributed under the terms of GNU GPL version 2 or later
#
+
    #
# Install in your ~/Nautilus/scripts directory.
+
    # Install in your ~/Nautilus/scripts directory.
# You need to be running Nautilus 1.0.3+ to use scripts.
+
    # You need to be running Nautilus 1.0.3+ to use scripts.
cd $NAUTILUS_SCRIPT_CURRENT_URI
+
   
exec gnome-search-tool
+
    cd $NAUTILUS_SCRIPT_CURRENT_URI
 +
    exec gnome-search-tool
 
</nowiki></pre>
 
</nowiki></pre>
 
=== Open terminal here ===
 
=== Open terminal here ===
 
[[Top Back to top]]
 
[[Top Back to top]]
 
<pre><nowiki>
 
<pre><nowiki>
#!/bin/bash
+
    #!/bin/bash
#
+
    #
# This script opens a gnome-terminal in the directory you select.
+
    # This script opens a gnome-terminal in the directory you select.
#
+
    #
# Distributed under the terms of GNU GPL version 2 or later
+
    # Distributed under the terms of GNU GPL version 2 or later
#
+
    #
# Install in ~/.gnome2/nautilus-scripts or ~/Nautilus/scripts
+
    # Install in ~/.gnome2/nautilus-scripts or ~/Nautilus/scripts
# You need to be running Nautilus 1.0.3+ to use scripts.
+
    # You need to be running Nautilus 1.0.3+ to use scripts.
# When a directory is selected, go there. Otherwise go to current
+
   
# directory. If more than one directory is selected, show error.
+
    # When a directory is selected, go there. Otherwise go to current
if [ -n "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ]; then
+
    # directory. If more than one directory is selected, show error.
set $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
+
    if [ -n "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ]; then
if [ $# -eq 1 ]; then
+
        set $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
destination="$1"
+
        if [ $# -eq 1 ]; then
# Go to file's directory if it's a file
+
            destination="$1"
if [ ! -d "$destination" ]; then
+
            # Go to file's directory if it's a file
destination="`dirname "$destination"`"
+
            if [ ! -d "$destination" ]; then
fi
+
                destination="`dirname "$destination"`"
else
+
            fi
zenity --error --title="Error - Open terminal here" \
+
        else
--text="You can only select one directory."
+
            zenity --error --title="Error - Open terminal here" \
exit 1
+
              --text="You can only select one directory."
fi
+
            exit 1
else
+
        fi
destination="`echo "$NAUTILUS_SCRIPT_CURRENT_URI" | sed 's/^file:\/\///'`"
+
    else
fi
+
        destination="`echo "$NAUTILUS_SCRIPT_CURRENT_URI" | sed 's/^file:\/\///'`"
# It's only possible to go to local directories
+
    fi
if [ -n "`echo "$destination" | grep '^[a-zA-Z0-9]\+:'`" ]; then
+
   
zenity --error --title="Error - Open terminal here" \
+
    # It's only possible to go to local directories
--text="Only local directories can be used."
+
    if [ -n "`echo "$destination" | grep '^[a-zA-Z0-9]\+:'`" ]; then
exit 1
+
        zenity --error --title="Error - Open terminal here" \
fi
+
          --text="Only local directories can be used."
cd "$destination"
+
        exit 1
exec x-terminal-emulator
+
    fi
 +
   
 +
    cd "$destination"
 +
    exec x-terminal-emulator
 
</nowiki></pre>
 
</nowiki></pre>
 
=== Hide or Show Hidden Files ===
 
=== Hide or Show Hidden Files ===
 
[[Top Back to top]]
 
[[Top Back to top]]
 
<pre><nowiki>
 
<pre><nowiki>
#!/bin/sh
+
    #!/bin/sh
# When hidden files (.emacs, etc) are hidden, shows "Show Hidden Files" option.
+
    # When hidden files (.emacs, etc) are hidden, shows "Show Hidden Files" option.
# When hidden files are shown, shows "Hide Hidden Files" option.
+
    # When hidden files are shown, shows "Hide Hidden Files" option.
# Uses gconf to toggle between the two Nautilus options.
+
    # Uses gconf to toggle between the two Nautilus options.
# Should be placed in ~/.gnome2/nautilus-scripts/ with executable permission.
+
    # Should be placed in ~/.gnome2/nautilus-scripts/ with executable permission.
OLDSTATE=$(gconftool-2 --get "/desktop/gnome/file_views/show_hidden_files")
+
    OLDSTATE=$(gconftool-2 --get "/desktop/gnome/file_views/show_hidden_files")
if [ "$OLDSTATE" == "false" ] ; then
+
    if [ "$OLDSTATE" == "false" ] ; then
NEWSTATE="True"
+
      NEWSTATE="True"
mv ~/.gnome2/nautilus-scripts/Show\ Dot\ Files ~/.gnome2/nautilus-scripts/Hide\ Dot\ Files
+
      mv ~/.gnome2/nautilus-scripts/Show\ Dot\ Files ~/.gnome2/nautilus-scripts/Hide\ Dot\ Files
else
+
    else
NEWSTATE="False"
+
      NEWSTATE="False"
mv ~/.gnome2/nautilus-scripts/Hide\ Dot\ Files ~/.gnome2/nautilus-scripts/Show\ Dot\ Files
+
      mv ~/.gnome2/nautilus-scripts/Hide\ Dot\ Files ~/.gnome2/nautilus-scripts/Show\ Dot\ Files
fi
+
    fi
gconftool-2 --set "/desktop/gnome/file_views/show_hidden_files" --type boolean $NEWSTATE
+
    gconftool-2 --set "/desktop/gnome/file_views/show_hidden_files" --type boolean $NEWSTATE
 
</nowiki></pre>
 
</nowiki></pre>
 
Note:  You can do the same without a script by pressing CTRL+H under Nautilus
 
Note:  You can do the same without a script by pressing CTRL+H under Nautilus

2007年12月6日 (四) 10:47的版本

Anchor(Top) IconsPage?action=AttachFile&do=get&target=IconNautilus.png The nautilus file manager is extensible through the use of scripts.

Introduction

Purpose

With scripts you can do many things such as :

  • make an enhanced "open with"-alike feature (open some files that match a filter in your preferred application
  • make a zip of a directory and mail it
  • open a terminal in the selected directory
  • ...

all of this with a simple right click. Top Back to top

Managing Nautilus scripts

NautilusScriptsHowto?action=AttachFile&do=get&target=nautilus_folder.png All of your scripts are stored in the Nautilus-scripts folder - so to add a new script, simply place it there. You can find the Nautilus-scripts folder here :

     ~/.gnome2/nautilus-scripts

Top Back to top

Adding scripts

  • Open a text editor, copy/paste them into it,and save the script in you nautilus-scripts folder
  • name them accordingly to the label you want in the right-click context menu
  • make them executable (`chmod +x my_script_name`, or right-click on the script, select properties, then permissions, and give allow it to be executable)

That's it! {i} You will not have a `File->Scripts` nor see a `Scripts` entry in the context menu until you first add files there

Removing scripts

  • simply remove them from the nautilus-scripts folder

Setting rights to your scripts

IconsPage?action=AttachFile&do=get&target=IconWarning3.png You may need to run some scripts as a root user, this is generally a bad idea, unless you
know what you are doing. Setting appropriate rights can be done thanks to the `chmod` command. Top Back to top

Scripting

What is a script ?

You can place in the nautilus several "scripts", they can be :

  • binaries (compiled programs)
  • shell scripts (bash, sh ...)
  • ...

that is to say basically anything that can be run Top Back to top

Environment variables

Whenever a script is called, nautilus set some variables that can be used in your scripts. These are :

  • `NAUTILUS_SCRIPT_SELECTED_FILE_PATHS`

newline-delimited paths for selected files (only if local)

  • `NAUTILUS_SCRIPT_SELECTED_URIS`

newline-delimited URIs for selected files

  • `NAUTILUS_SCRIPT_CURRENT_URI`

current location

  • `NAUTILUS_SCRIPT_WINDOW_GEOMETRY`

position and size of current window Top Back to top

Sample scripts

Notes: These scripts may be out of date. Use at your own risk

Email the selected file

Top Back to top This one is really useful. How many times have you needed to find a file and then send it? And to be honest, from Evolution or mozilla-thunderbird this is not that simple. It is much easier to use Nautilus to find your file and then send it from there.

    #!/usr/bin/perl -w
    # By John Russell

    # This script sends the selected file(s) with your email client.

    use strict;

    my $MAILTO_URL="mailto:?";
    my @files = split("\n", $ENV{NAUTILUS_SCRIPT_SELECTED_FILE_PATHS});
    my $count = 0;
    foreach my $file (@files)
    {
        if ( ! -f $file && ! -l $file )
        {
            my @dialog = ("gdialog","--title","Error","--msgbox", "\nError: Can not send $file.    \n\n    Only regular files can be mailed.    ","200", "300");
            system (@dialog);
    	}
    	else
    	{
    	   $MAILTO_URL = $MAILTO_URL . "attach=" . $file . "&";
               shift;
    	    $count += 1;
    	}
    }


    if ($count > 0)
    {
        my @command = ("gnome-open", $MAILTO_URL);
        system(@command);
    }

Added by Darrell: I found that the mailto: syntax in the above does not work with mozilla-thunderbird. I have created the following amended version which seems to work with Thunderbird:

    #!/usr/bin/perl -w
    # By John Russell
    # and hacked to work with thunderbird by Darrell

    # This script sends the selected file(s) with mozilla-thunderbird.

    use strict;

    my $attach_string="\"attachment='";
    my @files = split("\n", $ENV{NAUTILUS_SCRIPT_SELECTED_FILE_PATHS});
    my $count = 0;
    foreach my $file (@files)
    {
        if ( ! -f $file && ! -l $file )
        {
            my @dialog = ("gdialog","--title","Error","--msgbox", "\nError: Can not send $file. \n\n    Only regular files can be mailed.    ","200", "300");
            system (@dialog);
        }
        else
        {
           $attach_string = $attach_string . "file://" . $file . ",";
               shift;
            $count += 1;
        }
    }


    if ($count > 0)
    {
        $attach_string = $attach_string . "'\"";
    # replace spaces with '%20' as demanded by mozilla/thunderbird    
        $attach_string =~ s/\s/%20/g;
    # invoke shell script to call thunderbird differently depending on whether it's running already or not
        my $command = ("~/scripts/thunderbird-email-attachments " . $attach_string);
        system($command);
    }

You will see there is also a shell script which is required, (~/scripts/thunderbird-email-attachments in my example above, don't put it in the nautilus-scripts directory, otherwise it will show up in the context menu):

    #!/bin/sh

    # if thunderbird is already running open a compose window in the running instance

	    if `ps xc | grep -q mozilla-thunder`; then 
		    exec mozilla-thunderbird -a Mozilla-Thunderbird -remote         "xfeDoCommand(ComposeMessage,$1)"

    # else start a new instance with the compose window only

	    else
		    exec mozilla-thunderbird -compose $1 
	    fi

Mount ISO

Top Back to top Mount an ISO image, from Nautilus. Note from carney1979 - this script will be updated to work with filenames containing spaces soon.

    #!/bin/bash
    #
    #By modprobing loop it makes sure that the module is loaded and ready for 
    #use.  If it is already loaded then nothing will happen.
    modprobe loop
    for I in `echo $*`
    do
       foo=`gksudo -u root -k -m "enter your password for root terminal access" /bin/echo "got r00t?"`
    sudo mount -o loop -t iso9660 $I /media/iso
       done
    done
    exit0

Unmount ISO

Top Back to top Unmount an iso image, from nautilus. Note from carney1979 - this script will be updated to work with filenames containing spaces soon.

    #!/bin/bash
    #
    for I in `echo $*`
    do
       foo=`gksudo -u root -k -m "enter your password for root terminal access" /bin/echo "got r00t?"`
    sudo umount $I
      done
    done
    exit0

Set file read-only

Top Back to top Change file-permission to read-only.

    #!/bin/bash

    chmod ugo-wx $*

Edit file with gedit with root-privileges

Top Back to top Note from carney1979 - this script will be updated to work with filenames containing spaces soon.

    #!/bin/bash
    #
    for I in `echo $*`
    do
       foo=`gksudo -u root -k -m "enter your password for root terminal access" /bin/echo "got r00t?"`
    sudo gedit $I
       done
    done
    exit0

Open Nautilus with root-privileges here

Top Back to top

    #!/bin/bash
    # root-nautilus-here
    # opens a root-enabled instance of a nautilus window in selected location
    # requires sudo privileges and gksudo, which may involve security risks.
    #Install in your ~/Nautilus/scripts directory.
    #
    # Placed in the public domain by Shane T. Mueller 2001
    # Fixes provided by Doug Nordwall
    #
    # 2004.04.18 -- [email protected] - Added gksudo usage to provide popup
    #               password window if sudo has expired.  Line only echos got
    #               root to std output.  But gksudo updates your sudo access
    #               privs, so running nautilus with sudo will succeed
    #               without asking for a password.
    
    
    foo=`gksudo -u root -k -m "enter your password for nautilus root access" /bin/echo "got r00t?"`
    sudo nautilus --no-desktop $NAUTILUS_SCRIPT_CURRENT_URI

Run file with root privileges

Top Back to top Note from carney1979 - this script will be updated to work with filenames containing spaces soon.

    #!/bin/bash
    #
    for I in `echo $*`
    do
       /usr/bin/gksudo $I
       done
    done
    exit0

Open search window here

Top Back to top

    #!/bin/sh
    # From Johnathan Bailes
    # This script opens a gnome-search-tool in the directory you select.
    #
    # Distributed under the terms of GNU GPL version 2 or later
    #
    # Install in your ~/Nautilus/scripts directory.
    # You need to be running Nautilus 1.0.3+ to use scripts.
    
    cd $NAUTILUS_SCRIPT_CURRENT_URI
    exec gnome-search-tool

Open terminal here

Top Back to top

    #!/bin/bash
    #
    # This script opens a gnome-terminal in the directory you select.
    #
    # Distributed under the terms of GNU GPL version 2 or later
    #
    # Install in ~/.gnome2/nautilus-scripts or ~/Nautilus/scripts
    # You need to be running Nautilus 1.0.3+ to use scripts.
    
    # When a directory is selected, go there. Otherwise go to current
    # directory. If more than one directory is selected, show error.
    if [ -n "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ]; then
        set $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
        if [ $# -eq 1 ]; then
            destination="$1"
            # Go to file's directory if it's a file
            if [ ! -d "$destination" ]; then
                destination="`dirname "$destination"`"
            fi
        else
            zenity --error --title="Error - Open terminal here" \
               --text="You can only select one directory."
            exit 1
        fi
    else
        destination="`echo "$NAUTILUS_SCRIPT_CURRENT_URI" | sed 's/^file:\/\///'`"
    fi
    
    # It's only possible to go to local directories
    if [ -n "`echo "$destination" | grep '^[a-zA-Z0-9]\+:'`" ]; then
        zenity --error --title="Error - Open terminal here" \
           --text="Only local directories can be used."
        exit 1
    fi
    
    cd "$destination"
    exec x-terminal-emulator

Hide or Show Hidden Files

Top Back to top

    #!/bin/sh
    # When hidden files (.emacs, etc) are hidden, shows "Show Hidden Files" option.
    # When hidden files are shown, shows "Hide Hidden Files" option.
    # Uses gconf to toggle between the two Nautilus options.
    # Should be placed in ~/.gnome2/nautilus-scripts/ with executable permission.
    OLDSTATE=$(gconftool-2 --get "/desktop/gnome/file_views/show_hidden_files")
    if [ "$OLDSTATE" == "false" ] ; then
      NEWSTATE="True"
      mv ~/.gnome2/nautilus-scripts/Show\ Dot\ Files ~/.gnome2/nautilus-scripts/Hide\ Dot\ Files
    else
      NEWSTATE="False"
      mv ~/.gnome2/nautilus-scripts/Hide\ Dot\ Files ~/.gnome2/nautilus-scripts/Show\ Dot\ Files
    fi
    gconftool-2 --set "/desktop/gnome/file_views/show_hidden_files" --type boolean $NEWSTATE

Note: You can do the same without a script by pressing CTRL+H under Nautilus


Top Back to top

Links