4

Pressing Alt+Home in Nautilus takes my directly to /homer/user. This is very convenient!

I would like to setup a custom keyboard shortcut for an arbitrary folder in my system, since besides /home/user there are a few other folders I need to access frequently when going through various folders on my system (e.g. /media/user/my_pictures, if I have mounted an external hard drive containing a lot of pictures and videos I have taken).

I would like one single shortcut combination to take my there; that means no fiddling solutions, such as bookmarking the folder, then entering with F6 the bookmarks tab and then navigating there to the desired folder. It has to be done in one stroke, just like Alt+Home takes me to my home folder.

l7ll7
  • 395

2 Answers2

2

In Nautilus, it is unfortunately not possible to assign a shortcut key to open a bookmark, or otherwise display the contents of a specific folder in the current window. The command line interface of nautilus also is extremely limited. It is easy enough to create shortcut keys that opens a folder in a new window, but it is not obvious to change the displayed folder in the current window using a shortcut key.

Potentially, the nautilus-python API exposes the needed functionality, but this requires some programming skills and access to the apparently quite hidden documentation. We hope such answer will come along.

Following is only a hack. Keyboard input to change to another folder using the pathbar is generated using xdotool. This can be started from within nautilus using a nautilus script. There is an obscure feature of nautilus, where one can define a shortcut to execute a script. All together, this would give the effect we are after.

Hack using xdotool

  1. Create a nautilus script:

    gedit ~/.local/share/nautilus/scripts/_1 Documents

  2. Paste the following code for the script:

code

#!/bin/bash
DESTINATION=~/Documents
OLDSELECT=$(mktemp)
echo "$DESTINATION" | xsel -bi
xdotool sleep 0.2 key Control+l Control+v Return
xsel -bi < "$OLDSELECT" ; rm "$OLDSELECT"

/code

  1. Define a shortcut key for the script:

    gedit ~/.config/nautilus/scripts-accels

  2. Add a line looking like

    <Control>0 _1 Documents

This implements a shortcut key Ctrl+0 that will change the current view to the desired folder, ~/Documents in this example. It simulates opening the path bar (Ctrl+L, then pasting the folder path, then hitting Enter.

The script saves textual content that currently may be in the clipboard, stores the desired pathname in the clipboard, then uses xdotool to change the folder using the pathbar. As usual, a small delay (sleep 0.2) is needed to make the script more reliable.

It is a hack. There are several caveats:

Caveat 1: will not work on Wayland

xdotool and xsel do not work on Wayland, the default display server starting from Ubuntu 21.10. Either change to the Xorg session, or adapt the script. Tools like ydotool and wl-clipboard can simulate keyboard input and manipulate the clipboard on Wayland.

Caveat 2: scripts-accels broken in some versions of Nautilus

~/.config/nautilus/scripts-accels, the configuration file that allows to assign shortcut keys to scripts, is broken on Ubuntu 20.04. It worked before, and, fortunately, works again on Files 40.2 (Ubuntu 21.10).

Workaround

One may define desktop wide shortcut keys instead, and in the script, check whether the active window is Nautilus before executing the rest (wmctrl). Drawback: these keys cannot anymore be used in another application/context for something else.

Caveat 3: limited keys can be assigned

The mechanism ~/.config/nautilus/scripts-accels does not allow to override existing keys. For example, keys like <Control>1 and <Control>2 are already used to change the nautilus view. <Alt># keys are already used to change tabs. So experiment which work and which not. Keys are defined like:

; Example Keybinds
; Modifiers: <Control> <Alt> <Shift>
; F4 open-terminal-here
; <Alt>x remove-extension
vanadium
  • 97,564
1

In GNOME, you can set a custom keyboard shortcuts to open Nautilus at specific folder.

Go Settings > Keyboard > View and Customize Shortcuts > Custom Shortcuts and use the command

nautilus /home/user/Downloads/

to make Nautilus open a new window with your Downloads folder open.

You may not always want to open a new window. Perhaps you have a Downloads window open somewhere. To bring that window to the front, you can use the excellent and very versatile Run or Raise extensions.

Bonus: Both Dolphin and PCManFM allows you to define system-level shortcuts that open new tabs at specified locations in the currently open window. With Run or Raise, you can then have just one file manager window open.

Rasmus
  • 8,655