How to add keyboard shortcut for custom nemo action?

2k Views Asked by At

I have an custom nemo action as explained here: https://wiki.archlinux.org/index.php/Nemo#Nemo_Actions

How can I add an shortcut for this action?

(If it can be done adding a line in ~/.gnome2/accels/nemo, then I have the additional problem that on my system this file is auto generated on every reboot, so editing something here will not help. I have Cinnamon 3.2.7 and nemo 3.2.2.)

Any suggestions? Thanks in advance! :)

2

There are 2 best solutions below

2
On

Am trying to respond to Duncan Marshall but the post ended up in the mainthread. Yes, it's possible. Your file ~/.gnome2/accels/nemo can contain a line such as the following, which would execute a scrip file named edit.sh when F4 is pressed. The scripfile must be located in this special path (~/.local/share/nemo/scripts) and it must be enabled via a checkbox in User Interface>Edit>Preferences>Plugins>Scripts. Also i was unable to specify a script path such as ~/... instead of /home/username... When the syntax in the accels/nemo file is incorrect, nemo will prepend the incorrect line with ; and it will also delete the keycode at the end of the line and it also likes to resort lines in the accels file. I will also dismiss a line when the keycode was already used in another line. So it couldn't be more tricky to get this right.

(gtk_accel_path "<Actions>/ScriptsGroup/script_file:\\s\\s\\shome\\sUSERNAME\\s.local\\sshare\\snemo\\sscripts\\sedit.sh" "F4")

the script file might look like this

#!/bin/bash
export FILETOEDIT="$1"
FILEOWNER=$(stat -c %U "$1")
if [ "$FILEOWNER" = "$USER" ]; then
  subl "$1"
else
  sudo xed -w "$FILETOEDIT"
fi
1
On

Nemo Action

First, you should place the myaction.nemo_action under ~/.local/share/nemo/actions/.

Then, to make a keystroke put an underscore _ in front of the letter you want. For example in the Hello _Shortcut the s is the key. So you press the right-click and then s.

Bellow is an example of my action to open files and directories with Atom:

# Custom action for Nemo File Manager for Cinnamon.
# Adds right-click open file/files or directory with Atom.
# Place it under: ~/.local/share/nemo/actions/atom.nemo_action
# For more info: https://github.com/linuxmint/nemo/blob/master/files/usr/share/nemo/actions/sample.nemo_action

[Nemo Action]
Active=true
Name=Open in _Atom
Comment=Open %F in Atom
Exec=atom %F
Icon-Name=atom
Selection=any
Extensions=any;
Dependencies=atom;
Quote=double

Global Shortcut

If you want a global shortcut, you should use the Cinnamon Keyboard setting under the System settings, go to the second tab and add your custom shortcut.
Or, if you prefer more control over CLI you can use the dconf. For example, the bellow configuration will add the shortcut Shift><Alt>a

/org/cinnamon/desktop/keybindings/custom-keybindings/custom0/name
  'Open Atom'
/org/cinnamon/desktop/keybindings/custom-keybindings/custom0/command
  'atom'
/org/cinnamon/desktop/keybindings/custom-keybindings/custom0/binding
  ['<Shift><Alt>a']
/org/cinnamon/desktop/keybindings/custom-list
  ['custom0']