SEARCH

How-To Geek

Add "Open with gedit" to the right click menu in Ubuntu

The file browser in Ubuntu provides the ability to run scripts on a selected file. These scripts can be used to do anything from opening a file to zipping or uploading, or anything that you can do from the command line.

To start off, we will need to open a terminal window and type in the following command, which will create a new script file in our nautilus scripts directory

gedit ~/.gnome2/nautilus-scripts/Open\ with\ gedit

Paste in the following script, found on the G-Scripts site, which is a great resource for finding scripts.

#!/bin/bash
#
# Nautilus script -> open gedit
#
# Owner : Largey Patrick from Switzerland
#     patrick.largey@nazeman.org
# www.nazeman.org
#
# Licence : GNU GPL
#
# Copyright (C) Nazeman
#
# Ver. 0.9-1 Date: 16.02.2002
# Add multiple file open in the same windows
#
# Ver: 0.9  Date: 27.10.2001
# Initial release
#
# Dependence : Nautilus (of course)
#   Gnome-utils (gdialog)
#
filesall=”"
while [ $# -gt 0 ]
do
files=`echo “$1″ | sed ‘s/ /\?/g’`
filesall=”$files $filesall”
shift
done
gedit $filesall&

Save and close the gedit window, and then execute the following command to make the script executable:

chmod u+x ~/.gnome2/nautilus-scripts/Open\ with\ gedit

Note that tab completion really helps here =)

Now when you right click a file, you should see this:

Tested on: Ubuntu Dapper, Ubuntu Edgy Eft

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 10/20/06

Comments (17)

  1. Dan Vokt

    Typo:
    The char after $1 is NOT an ASCII double quote (0×22) – it is a Unicode double prime U+2033

    IS:
    files=`echo “$1″ | sed ‘s/ /\?/g’`

    SHOULD BE:
    files=`echo “$1″ | sed ‘s/ /\?/g’`

  2. Noel

    when i open a file with gedit using the open with gedit script it doesnt display any text although it will if i open a text file within gedit.

  3. nqsonk9

    Try this:
    #########################
    filesall=”"
    while [ $# -gt 0 ]
    do
    files=`echo “$1″ | sed ‘s/ /\?/g’`
    filesall=”$files $filesall”
    shift
    done
    gedit $filesall&
    #########################

  4. 3r1c

    ThX mate,this is what i needed!

  5. kah00na

    I did not know you could do this. I have to convert movie files from my flash video camera so they in a better playable format. I’ve been using the command line to do this. I’m going to use the same concept to make a right-click script to do this! Great post!

  6. blu

    for me worked with:

    gedit /home/user/.gnome2/nautilus-scripts/Open\ with\ gedit

    8.04

  7. astralnaut

    Thanks again Geek,for another successful tip. Used on Hardy Heron.

  8. airtonix

    or you can just “open with other application” -> choose “text editor” (which is gedit)….now you have open with gedit in your right click menu

  9. malac

    #!/bin/bash
    #
    # Nautilus script -> open gedit
    #
    gedit $NAUTILUS_SCRIPT_SELECTED_URIS

    In the interests of brevity the above code does exactly the same thing. :)

  10. Michael

    How to uninstall the script?

  11. BloggerTinker

    Thanks HTG! It worked perfectly for me.

    @Michael
    just go to the file directory ~/.gnome2/nautilus-scripts.
    Commands:

    cd ~/.gnome2/nautilus-scripts:
    rm Openwithgedit

    Note: please make sure you deleted the correct file as there is no UNDO with the terminal (as I have learned)

    BloggerTinker
    Ubuntu 8.04.1
    Linux Complete Newbie

  12. kyle2595

    When I use “Open With gedit” from the right click menu in Ubuntu 9.04, nothing happens, any help.

  13. Joewski

    The problem with the code snippet is that the quotation marks are not correct. You need to retype the quotes both single and double right through the entire script. Then it will work in 9.04. This is a bug with this web site.

  14. Guilherme - Milhouse

    It worked in Ubuntu 10.04, doing what Joewski explained.

    Thanks!

  15. Bri

    Replace the double quotes and apostrophes and it works!

  16. Marshall Neill

    As Malac said,
    #!/bin/bash
    #
    # Nautilus script -> open gedit
    #
    gedit $NAUTILUS_SCRIPT_SELECTED_URIS

    In the interests of brevity the above code does exactly the same thing. :)

    Worked perfectly.

  17. zelo

    The 2nd script worked for me too..ubuntu 11.04 was much needed because im trying to make mouse pointers and themes. always opening config files n such that dont register as openable with gedit ;)

Enter Your Email Here to Get Access for Free:

Go check your email!