[HowTo] add custom scripts to Nautilus right click menu and assign keyboard shortcuts

Difficulty: ★☆☆☆☆

Copied from old forum and updated.

Similar to Thunar’s custom actions feature, Nautilus has a custom scripts feature. If you create bash scripts in the ~/.local/share/nautilus/scripts folder (you need to create this folder), they appear in the right-click menu like this:

For more details go here

Here are my basic scripts:

  • compare-files

    #!/bin/bash
    meld ./"$@" &
    
    • Note: Install meld to use this script
  • convert-srt-to-utf8

    #!/bin/bash
    
    for f in "$@"
    do
    	mv ./"$f" ./"$f.bak"
    	iconv -f $(uchardet ./"$f.bak") ./"$f.bak" -t UTF-8 -o ./"$f"
    	trash ./"$f.bak"
    done
    
    notify-send "File(s) converted to UTF-8"
    
  • copy-path

    #!/bin/bash
    
    mypath=$(pwd)/"$1"
    echo -n $mypath | xclip -selection clipboard
    
    notify-send "Path copied to clipboard:" "$mypath"
    
  • create-backup

    #!/bin/bash
    
    for f in "$@"
    do
    	cp -r ./"$f" ./"$f".bak
    done
    
    notify-send "Backup(s) created"
    
  • create-link-hard

    #!/bin/bash
    
    for f in "$@"
    do
    	ln ./"$f" ./"$f".hardlink
    done
    
  • create-link-soft

    #!/bin/bash
    
    for f in "$@"
    do
    	ln -s ./"$f" ./"$f".softlink
    done
    
  • edit-image

    #!/bin/bash
    
    for f in "$@"
    do
    	ksnip -e $(pwd)/"$f" &
    done
    
    • Note: Install ksnip to use this script
  • edit-text

    #!/bin/bash
    gedit ./"$@" &
    
    • Note: Install gedit to use this script
  • find-subtitles

    #!/bin/bash
    qnapi "$@" &
    
    • Note: Install qnapi to use this script
  • rm-rf (This one is dangerous!)

    #!/bin/bash
    
    rm -rf ./"$@"
    
    foo=$@
    notify-send "Files removed:" "$foo"
    
  • search-in-folder

    #!/bin/bash
    catfish ./"$1" &
    
    • Note: Install catfish to use this script
  • show-disk-usage

    #!/bin/bash
    qdirstat ./"$1" &
    
    • Note: Install qdirstat to use this script
  • show-media-info

    #!/bin/bash
    
    for f in "$@"
    do
    	mediainfo-gui ./"$f" &
    done
    
  • upload-image

    #!/bin/bash
    
    for f in "$@"
    do
    	imgurbash2 ./"$f"
    done
    
    notify-send "Image link(s) copied to clipboard"
    

You can also create keyboard shortcuts for your custom scripts. For example in order to open terminal in the current folder with the keyboard shortcut F4, create the below 2 files:

  • ~/.local/share/nautilus/scripts/terminal

    #!/bin/bash
    gnome-terminal
    
  • ~/.config/nautilus/scripts-accels

    F4 terminal
    

    You can add multiple keyboard shortcuts to ~/.config/nautilus/scripts-accels

    F4 terminal
    F3 rm-rf
    

In order changes to take effect, quit nautilus with nautilus -q and open it again.

What are your custom scripts?

10 Likes

I’ve improved my scripts. Changes:

  • Multiple selection of files/folders is available for the most of the scripts.
  • Notification bubbles are added with libnotify.
  • convert-srt-to-utf8 script can detect original file’s charset.
  • edit-image and find-subtitles scripts are added.
  • & added after some commands.
  • Links to programs needed to run the scripts are added as notes.
2 Likes