Monday, March 22, 2010

Add file to VLC playlist by right clicking

I found a simple nautilus script which is very usefull for those who usually plays something in VLC. Script to add a file to VLC playlist by simple right clicking on the file .

What to do ?


cd ~/.gnome2/nautilus-scripts

touch "Add to VLC Playlist"

then copy the following to the file "Add to Playlist"

Pre-requisite: Install zenity from your package manager


#!/bin/bash

## Ny Narendra Sisodiya, for SchoolOS
## narendra.sisodiya@gmail.com
## modified by: IRFAN NASEEF P
##             irfan@nitc.ac.in

checkFileType()
{
  file $1 | grep -i "audio" || file $1 | grep -i "video" || file $1 | grep -i "ogv" || file $1 | grep -i "mpeg"
  RES=$?
  if [ $RES -eq 0 ]
  then
      return 0
  else
      zenity --error --title "VLC says: " --text "Error: $FILENAME is not an audio/video file"
      return 1
 
   
   fi
}

IFS=$'\n'
for FILENAME in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
do
  checkFileType $FILENAME

  if [ $? -eq 0 ]
  then
    vlc --started-from-file --one-instance-when-started-from-file --playlist-enqueue "$FILENAME"
    
 fi
done

exit 0

################

Then save ..

Now you can see a 'Scripts' option when you right click , and a 'Add to VLC Playlist' in it. Now you can directly add files to playlist by simply right clicking .