Open Nautilus as a new tab in an existing window

12,191

Solution 1

I wrote a bash script and a launcher for that.

  1. First, create the file:

    mkdir ~/bin && gedit ~/bin/nautilus-ctrl-t.sh
    
  2. Then paste the following, and save:

    if [ "$(wmctrl -xl | grep "nautilus\.Nautilus")" == "" ]; then
        nautilus "$1" &
    else  
        #Save old clipboard value
        oldclip="$(xclip -o -sel clip)"
    
        echo -n "$1" | xclip -i -sel clip
        #wmctrl -xF -R nautilus.Nautilus && xdotool key "ctrl+t" "ctrl+l" && xdotool type "${1}" && xdotool key Return
        wmctrl -xF -R nautilus.Nautilus && xdotool key ctrl+t ctrl+l ctrl+v Return
    
        #Restore old clipboard value
        echo -n "$oldclip" | xclip -i -sel clip
    fi
    
  3. Then run the command:

    sudo chmod u+x ~/bin/nautilus-ctrl-t.sh
    
  4. Now, to create the launcher file, run this command:

    gedit ~/.local/share/applications/Nautilus-Ctrl-t.desktop
    
  5. Paste the following, and save:

    [Desktop Entry]
    Type=Application
    Name=Nautilus-Ctrl-t
    Comment=Launches Nautilus if not yet, otherwise opens a new tab in it
    Categories=FileManager;GNOME;
    Icon=/usr/share/icons/gnome/48x48/apps/system-file-manager.png
    Exec=/bin/bash -c ~/bin/nautilus-ctrl-t.sh
    Terminal=false
    
  6. Log out, or restart to update the application list and you're done.

Try that. Hope it helps.

UPDATE

Added a location as a script parameter

UPDATE 2

Replaced xdotool type with xclip

UPDATE 3

Cleaned up the process by adding numbers. Added mkdir command. Updated the first "if statement" because if nautilus is managing the desktop, it will have a pid, but no active window, so better to use wmctrl. Added quotes around the first argument in case there are spaces. Changed the icon for nautilus to be system default in the .desktop file.

Solution 2

I believe it is not possible as
1) It is a suggested idea at Ubuntu Brainstorm that wasn't implemented yet,
2) And supposedly after analyzing the source code Shiki didn't find a way to pass this call to nautilus.

Solution 3

This is fixable very easily in CentOS 6.2 by going into the Nautilus preferences, on the "Behavior" tab and clicking the box called "Always open in browser windows".

You will know it worked because from that point on, in your folder browsing window, you will see a left hand nav on the window which is the method that Nautilus uses to "re-use" the explorer window.

So, basically, all you need to figure out is "how to enable the left-hand navigation menu in a Nautilus browser window".

Solution 4

Whatever desgua said is somewhat right.

One option you have is to press Ctrl + T to open a new tab in the same window.

Or press F3 in Nautilus for split view.

Share:
12,191

Related videos on Youtube

wim
Author by

wim

Hi from Chicago! Python dev with interest in mathematics, music, robotics and computer vision. I hope my Q&A have been helpful for you. If one of my answers has saved your butt today and you would like a way to say thank you, then feel free to buy me a coffee! :-D [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo *Click*

Updated on September 18, 2022

Comments

  • wim
    wim almost 2 years

    Currently, if I click a launcher, shortcut icon, etc., I will get a new Nautilus window. If there is already a Nautilus window open, I would rather it open up in a new tab in the existing window (as if I had done Ctrl + T and browsed to the new location). How can I make this happen?

    • Andrea Bertani
      Andrea Bertani almost 13 years
      Some applications have a command-line option for this sort of thing, but I don't find anything like that for Nautilus. I agree that would be useful though.
    • jrg
      jrg over 12 years
      Are you still experiencing this issue?
  • Jeremy Bicha
    Jeremy Bicha about 12 years
    You'll need to install xdotool and wmctrl for that script to work, as they're not installed by default.
  • int_ua
    int_ua about 12 years
    Thanks for your attention, but it's not about opening new tabs from within Nautilus :)
  • int_ua
    int_ua about 12 years
    Well, it's a dirty hack, but I hope it'll work in most cases :) Can you please add passing location as the argument? It looks like possible with "Ctrl+L", insert passed address, "Enter"...
  • int_ua
    int_ua about 12 years
    I'm awarding desgua right now, but I promise you another bounty if you will add custom location opening to your script :)
  • desgua
    desgua about 12 years
    Thank you. Although the others answers are also interesting ;-)
  • int_ua
    int_ua about 12 years
    Yes, they are all good in some way :) And zuba will get another bounty if his hack will fix the initial issue :)
  • zuba
    zuba about 12 years
    Added a location as a script parameter.
  • int_ua
    int_ua about 12 years
    Ok, I've started a bounty for you, but AFAIU I can't award two bounties in one day :) There's a space missing after $pid and it doesn't work for inode/directory MIME type for me. Can you please add instructions on how to make it work for desktop shortcuts? Another suggestion is to use xclip for pasting location to avoid triggering some actions if Ctrl+L fails :)
  • zuba
    zuba about 12 years
    Added a space. Do you mean how make it work for existing nautilus shortcuts, or how to create a new shortcut to some folder opening? I'll try xclip in the evening.
  • desgua
    desgua about 12 years
    That would be 2.28.4 which is for Gnome-2 (GTK+2).
  • zuba
    zuba about 12 years
    As I see wmctrl key does the same as xclip. Doesn't it? What kind of shortcuts do you mean?
  • int_ua
    int_ua about 12 years
    I meant to replace nautilus with this script as default inode/directory handler :) xclip instead of xdotool type
  • zuba
    zuba about 12 years
    I have no idea how to utilise xclip instead of wmctrl, cause wmctrl deals with windows and X11 events, while xclip deals with clipboard and stdin/stdout which are rather different interfaces. Why not you assign promised bounty?
  • int_ua
    int_ua about 12 years
    The system didn't allow me to award twice in one day. Here you go :) But don't misinterpret me, I've never said about replacing wmctrl with xclip, did I? xclip is the clipboard manager, I'm suggesting to replace xdotool type with it :) (the problem is that xdotool type cannot type some characters and it's generally safer and faster to just paste the address instead of typing it)
  • int_ua
    int_ua about 12 years
    I will try to fix it myself later, don't worry ;)
  • zuba
    zuba about 12 years
    Ok, I get. I updated the script - changed xdotool type to xclip. Thanks.
  • djangofan
    djangofan about 12 years
    That being the case, it sounds like there is no solution for Gnome-3 ?
  • wim
    wim about 12 years
    This script is not quite working for me. It does open a new tab if nautilus is already open, but it doesn't start a new window otherwise. And I was not able to see how to make it open a custom location
  • Aquarius Power
    Aquarius Power over 9 years
    try to use ctrl+shift+t as this script does with --continue option, will work much better and much faster
  • chelder
    chelder over 9 years
    I have installed xdotool, wmctrl and wclick. I have executed exo-preferred-applications to set ~/bin/nautilus-ctrl-t.sh as the default file manager. Unfortunately, when I click on folders placed in the desktop they are opened in different windows. Also, the same folder is opened in a new tab when I open a different folder! Do you know another file browser able to do that without scripting: askubuntu.com/questions/586503/…