I've setup a Nautilus Script. I've put the script in /home/sumeet/.local/share/nautilus/scripts
and it does appear in right click menu. and also works as expected. I just want to assign a shortcut to the script.
How can I create keyboard shortcuts for my nautilus scripts?
Answers given in the question above target a specific release and are completely outdated, and I couldn't find anything other than this question concerning this topic.
How it can be done
When you right- click a file or folder for a nautilus script, the selected file is passed as an argument to the script. In most cases by something like:
...using python3, in its simplest form.
If you replace this by:
...the currently selected file is used inside the script as an argument
What you need
To use this solution (16.04 and up), you need to install both
xdotool
andpython3-pyperclip
:The complete script, mentioned in comments
then becomes:
Adding this to a shortcut key will set the icons for all directories inside the selected one.
Adding it to a shortcut key (!)
Adding shortcut keys, running (scripts using-)
xdotool
commands to press another key combination can be tricky. To prevent both key combinations to interfere with each other, use:Explanation
When Ctrl+C is pressed while a file is selected, the path to the file is copied to the clipboard. We are simulating the key press with:
python
'spyperclip
module simply produces the path, stripped fromfile://
when usingpyperclip.paste()
(this will not literally paste, but make the path available inside the script).If the goal is to select files and execute actions it's possible to do it using just shell script with
xdotool
andxclip
. So first install them:And then create the following script with the actions inside the loop:
This script doesn't rely on the NAUTILUS variables and you can create a shortcut with it:
_
in the name of the nautilus script, you can assign a hotkey to a script. e.g, a script named "_Combine PDF" will show up with the C underlined. When a file is selected, you can quickly access the script with Shift+F10 c.You can organize your scripts in subfolders. These subfolders also appear as menu choices, leading to a submenu. They also can be assigned a hotkey with this naming convention.