View Full Version : HOWTO: Quickly Open a Terminal From Nautilus
bobmitch
April 13th, 2005, 01:35 PM
This has probably been covered before, but I couldn`t see it anywhere...
Anyway, this is a quick method of dropping to a terminal from nautilus, which automatically changes directory to wherever you were browsing with nautilus. (For any local location - won`t work with ftp or other esoteric locations).
Big thanks to the guys in the Drag and Drop To Run As Root HOWTO thread (http://www.ubuntuforums.org/showthread.php?t=24008&highlight=open+root) for showing me how this could be achieved.
HOWTO: Quickly Open a Terminal From Nautilus
Open a Terminal
Type:
cd ~/.gnome2/nautilus-scripts
Type:
gedit Open\ Terminal\ Here
Paste the following code into the file:
#!/bin/sh
# From Chris Picton
# Replaces a Script by Martin Enlund
# Modified to work with spaces in path by Christophe Combelles
# This script either opens in the current directory,
# or in the selected directory
base="`echo $NAUTILUS_SCRIPT_CURRENT_URI | cut -d'/' -f3- | sed 's/%20/ /g'`"
if [ -z "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ]; then
dir="$base"
else
while [ ! -z "$1" -a ! -d "$base/$1" ]; do shift; done
dir="$base/$1"
fi
gnome-terminal --working-directory="$dir"
Save the gedit file, and quit.
Back in the terminal type:
chmod +x Open\ Terminal\ Here
et voila....
In any nautilus window, you can right click, and from the scripts sub-context-menu, click on Open Terminal Here to open a terminal at the currently viewed directory.
[EDIT] You can now highlight a folder and perform the operation to open a terminal at the location highlighted.
Hope somebody besides me finds this useful - the lack of this option has driven me batty since my foray into linux. :)
jonny
April 13th, 2005, 02:16 PM
Works perfectly. You just got rid of the last advantage KDE has over Gnome.
frühstück
April 13th, 2005, 02:23 PM
good idea
luca_linux
April 13th, 2005, 02:29 PM
Works perfectly. You just got rid of the last advantage KDE has over Gnome.
Yeah, Gnome rulez!
Spudgun
April 13th, 2005, 02:44 PM
Good stuff :grin:
shakin
April 13th, 2005, 02:57 PM
Great how-to. I didn't realize how useful this was until I tried it and now I can't live without it!
Do you know if there is a manual to see what variables are available? For instance, there is $NAUTILUS_SCRIPT_CURRENT_URI and $NAUTILUS_SCRIPT_SELECTED_URIS. Any more? I bet a lot of useful scripts can be made. In fact, I'm going to make a couple right now and do how tos if they work well.
bobmitch
April 13th, 2005, 03:01 PM
Great how-to. I didn't realize how useful this was until I tried it and now I can't live without it!
Do you know if there is a manual to see what variables are available? For instance, there is $NAUTILUS_SCRIPT_CURRENT_URI and $NAUTILUS_SCRIPT_SELECTED_URIS. Any more? I bet a lot of useful scripts can be made. In fact, I'm going to make a couple right now and do how tos if they work well.
The quick answer to your question is "Yes".
The long answer is taken from the "About Scripts" dialog:
When executed from a local folder, scripts will be passed the selected file names. When executed from a remote folder (e.g. a folder showing web or ftp content), scripts will be passed no parameters.
In all cases, the following environment variables will be set by Nautilus, which the scripts may use:
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: URI for current location
NAUTILUS_SCRIPT_WINDOW_GEOMETRY: position and size of current window
There's tons of useful things which can be done with this - the terminal launcher is the only one I could think of that was bothering me enough to make me implement something though. :D
I look forward to seeing anything you come up with. :)
shakin
April 13th, 2005, 03:05 PM
Great how-to. I didn't realize how useful this was until I tried it and now I can't live without it!
Do you know if there is a manual to see what variables are available? For instance, there is $NAUTILUS_SCRIPT_CURRENT_URI and $NAUTILUS_SCRIPT_SELECTED_URIS. Any more? I bet a lot of useful scripts can be made. In fact, I'm going to make a couple right now and do how tos if they work well.
To answer my own question, here are the available variables:
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
You can also use the gdialog application if your script needs user input.
--
dupe post. I spent too long browsing other scripts :)
bobmitch
April 13th, 2005, 03:16 PM
After some browsing, I came across a perl version (http://g-scripts.sourceforge.net/nautilus-scripts/Execute/Open%20Terminal%20Here) of my script. Lol.
Remix_88
April 13th, 2005, 03:18 PM
Take a look at G-Scripts :-)
http://g-scripts.sourceforge.net/
bobmitch
April 13th, 2005, 03:27 PM
Take a look at G-Scripts :-)
http://g-scripts.sourceforge.net/
Just been there, found a better bash script to use and updated my howto. :D
Nothing like re-inventing the wheel, eh? :D
XDevHald
April 13th, 2005, 03:44 PM
To make myself look like a n00b, I can't find my gnome2 folder, looked for 15 mins and still can't find it, I even have my Show Hidden Files selected.
shakin
April 13th, 2005, 03:47 PM
Take a look at G-Scripts :-)
http://g-scripts.sourceforge.net/
Yeah, when I found that I realized most of my ideas for scripts were already there. I'm still planning on making two file transfer scripts -- one for ftp and one for scp -- that ask for server and remote directory name using gdialog. Right now I'm having a bit of difficulty getting gdialog to do what I want.
Nis
April 13th, 2005, 04:01 PM
To make myself look like a n00b, I can't find my gnome2 folder, looked for 15 mins and still can't find it, I even have my Show Hidden Files selected.
Should be in ~/.gnome2
If you want to quickly get to the nautilus-scripts directory click on your desktop, press 'Ctrl+L', and put '~/.gnome2/nautilus-scripts/' into the dialog.
bobmitch
April 13th, 2005, 04:02 PM
Yeah, when I found that I realized most of my ideas for scripts were already there. I'm still planning on making two file transfer scripts -- one for ftp and one for scp -- that ask for server and remote directory name using gdialog. Right now I'm having a bit of difficulty getting gdialog to do what I want.
You might have more joy with zenity than gdialog?
Nis
April 13th, 2005, 04:05 PM
You might have more joy with zenity than gdialog?
zenity rocks. Much easier than gdialog. You can now even do notification icons with zenity.
minio
April 13th, 2005, 04:41 PM
There is an other way. You can install python-nautilus (not sure in which repository it is) and then copy open-terminal.py from /usr/share/doc/python-nautilus/examples/ to /usr/lib/nautilus/extensions-1.0/python/ . Restart nautilus and you will get Open terminal entry in right click menu.
XDevHald
April 13th, 2005, 05:06 PM
VERY impressive! and thank you for the help there Nis, much appreciated :grin:
Gandalf
April 13th, 2005, 05:15 PM
nice tick...... thanks
thepoch
April 17th, 2005, 11:56 AM
After some browsing, I came across a perl version (http://g-scripts.sourceforge.net/nautilus-scripts/Execute/Open%20Terminal%20Here) of my script. Lol.
Hehe, you found the one I modified. I would have written it as a bash script, but since I found that, I just fixed that (adding the 'opening on desktop' feature). I guess my 'fix' might no longer be needed in latter gnomes (never bothered hacking it again), but it still works for me since 2003.
:)
Sionide
May 24th, 2005, 05:41 PM
Well done, very very useful... I've always thought about the need for this.
bored2k
June 1st, 2005, 03:34 AM
Very useful. Thanks:D.
Basotang
July 28th, 2007, 10:27 AM
Hi,
I just followed that:
There is an other way. You can install python-nautilus (not sure in which repository it is) and then copy open-terminal.py from /usr/share/doc/python-nautilus/examples/ to /usr/lib/nautilus/extensions-1.0/python/ . Restart nautilus and you will get Open terminal entry in right click menu.
I now have a Open Terminal entry in the right click menu but nothing happens. Any idea why?
Thanks a lot in advance!
Seb.
Basotang
July 29th, 2007, 04:43 AM
Replying to my own message, login out and in again made the Open Terminal work.
Seb.
Samhain13
July 29th, 2007, 08:11 AM
Hello. I have been lurking in these forums but have not posted much.
I guess now I can just say "Thanks" for this handy script, which I need.
Cheers! :)
jpyanowski
July 29th, 2007, 11:08 PM
I want to add my thanks for this how-to. It makes using the terminal with nautilus so much easier. :)
mcduck
July 30th, 2007, 07:40 AM
What's the difference between this solution and the entry you get if you install 'nautilus-open-terminal' from repositories?
That one adds 'Open Terminal' to desktop right-click menu and 'Open Terminal Here' to Nautilus right-click menu..
Just run this, log out & back (or 'killall nautilus')
sudo apt-get install nautilus-open-terminal
Tuan Tran
July 30th, 2007, 02:44 PM
i must be retarded but where is the sub context menu :S tried right clicking everywhere lol...
Tuan Tran
July 30th, 2007, 02:49 PM
sry about that. i clt+alt+ backspace and logged back in and it worked. lol thx guys ! this is really handy for installing things. (unzip by the manager. browse it. open in terminal. ./configure and so on....)
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.