Nautilus Script to Launch a Terminal

August 12, 2009 by
Filed under: bash, gnome, HowTo, linux, Ubuntu 

I often find myself browsing my filesystem with Nautilus (the GNOME file manager) and wanting a terminal window to manipulate files in the current directory.  I decided to take a shot at writing my own Nautilus script to solve the problem. So here's my first Nautilus script. Save it in $HOME/.gnome2/nautilus-scripts. I named it terminal-here on my system.

#!/bin/bash
#
#  Nautilus script - terminal-here
#  This script will open a GNOME Terminal in the current directory.
#  Written by Linerd in August, 2009 - http://tuxtweaks.com/
#
#  Save this script under $HOME/.gnome2/nautilus-scripts/terminal-here. Make sure that
#  you give this file executable permission. { chmod +x terminal-here }
#
#  This program is free software.  It is distributed in the hope
#  that it will be useful, but WITHOUT ANY WARRANTY; without even
#  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
#  PURPOSE.  See the GNU General Public License for more details.
######################################################################

if [ "$NAUTILUS_SCRIPT_CURRENT_URI" == "x-nautilus-desktop:///" ]; then
        DIR=$HOME"/Desktop"
else
		DIR=`echo $NAUTILUS_SCRIPT_CURRENT_URI | sed 's/^file:\/\///' | sed 's/%20/ /g'`
fi

gnome-terminal --working-directory="$DIR"

exit 0

Make sure to make the file executable.

chmod +x ~/gnome2/nautilus-scripts/terminal-here

You can now launch a terminal by right clicking in Nautilus and selecting Scripts->terminal-here.

Being quite pleased with myself for my accomplishment, I then searched the web for similar solutions. Not only had others written scripts to do this, but some even chose the same name. The winner for being brief and simple was one I found on SourceForge, also called terminal-here.

Affiliate Link

I also found that there is also a plugin available for Nautilus that does the same thing. You can install it with

sudo apt-get install nautilus-open-terminal

You will need to log out and log back in for the plugin to show up in the context menu. It's nice that it's right there on the menu when you right click rather than being buried in a sub-menu under the Scripts menu.

I ended up finding a couple of better solutions than my own hack, but it was a good learning process.

Comments

5 Responses to “Nautilus Script to Launch a Terminal”

  1. Wikki says:

    Doesn't work for folders with UTF-8 character encoding.

  2. [...] following entry is based on the post “Nautilus Script to Launch a Terminal” by [...]

  3. Jabba says:

    Thanks, very useful for me. I knew about nautilus-open-terminal but I don't use it because of the lack of support for konsole. Your script with James' patch is just what I need.

  4. James says:

    Although the other script you mentioned is shorter, it doesn't work if you use konsole. I was able to adapt your version for use with konsole so it opens in nautilus' current directory!

    Simply replace the gnome-terminal line with:

    konsole --workdir "$DIR"

  5. Story added...

    This story has been submitted to fsdaily.com! If you think this story should be read by the free software community, come vote it up and discuss it here:

    http://www.fsdaily.com/Beginner/Launch_aTerminal_From_Nautilus...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>