• Enhancing contextual menus on Ubuntu Desktop

    Ubuntu desktop uses Gnome and its default desktop. You can add several interesting features to your contextual menus. ( You get a contextual menu when you right click on an object.). Let us see how we can add a simple script to the contextual menu.
    There is a special directory ( .gnome2/nautilus-scripts/ ) inside your home folder into which you can put your custom scripts. Any script you place in that location can be accessed by right-clicking on a file or window and selecting it from the Scripts sub menu. (The Scripts menu item will be visible only if you have some valid scripts installed.

    Let us try to open a terminal from the contextual menu. Change to the scripts directory. ( Note that .gnome is a hidden directory, try control -h in nautilus to see hidden files. )

    $ cd ~/.gnome2/nautilus-scripts/

    Create the following script

    Code:
     #!/bin/shgnome-terminal

    Save the file as myterminal
    Change the permission of the file and make it executable

    $ chmod u+x myterminal

    Now right click on the contextual menu. You should get it as below.

    When you execute a contextual menu script , a number of environment variables are passed to the script from nautilus. For example, if you select some files and then right click and select a script , the list of selected files will be passed to the script as an environment variable . You can use this variable inside the script for further processing.

    Some of the variables passed are.

    NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
    Newline-delimited paths for selected files if they are local
    NAUTILUS_SCRIPT_SELECTED_URIS
    Newline-delimited URIs for selected files
    NAUTILUS_SCRIPT_CURRENT_URI
    URI for current location
    NAUTILUS_SCRIPT_WINDOW_GEOMETRY
    Position and size of the current window

    Here is a bare minimum example with which you can try out the use of environment variable.

    Suppose you want to open a terminal and change to a particular directory, you can put the following code in nautilus-scripts directory. ( There is no error checking).

    Code:

     #!/bin/sh
    
    mydir=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHSif [ -d $mydir ]; thencd $mydirgnome-terminalexitfi
    

    Now right click and select the script. Your terminal will open with the selected directory as the working directory.

    There are a number of nautilus scripts available on the internet. In the ubuntu 9.04 repository, the following script collections are available.

    nautilus-script-audio-convert – A nautilus audio converter script
    nautilus-script-collection-svn – Nautilus subversion management scripts

    You can also get lot of useful scripts from http://g-scripts.sourceforge.net/.

    continue reading »

     
     
  • Edit Grub menu in Ubuntu

    Some days ago my Update Manager prompted saying it had some updates for my system. I allowed the updates to be installed and among them was an update for the Linux image. Everything went fine and I ended up with an updated system. It asked for reboot and reboot it had.
    On booting, the GRUB had [...]

    continue reading »

     
     
 
 
Extra Tags