Ubuntu – Open Nautilus as a new tab in an existing window

browsergnomenautilustabswindow-manager

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?

Best Answer

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.