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
Create a nautilus script:
gedit ~/.local/share/nautilus/scripts/_1 Documents
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
Define a shortcut key for the script:
gedit ~/.config/nautilus/scripts-accels
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