Scripting question (testing file extension)

Using applications, configuring, problems
Post Reply
Message
Author
User avatar
willhunt
Posts: 495
Joined: Wed 05 Oct 2005, 18:19

Scripting question (testing file extension)

#1 Post by willhunt »

I use the address bar in icewm because it is a very handy command line :D
so I found this little script that opens a file choose window

Code: Select all

#!/bin/sh

FILE=`Xdialog --title "Whats Next!" --fselect / 28 58 2>&1`

case $? in
   0)
      $1 "$FILE" ;;

   1)
      echo "Cancel pressed.";;
   255)
      echo "Box closed.";;
esac 
I would call it from the address bar with the application
I wanted to use
pick gxine
I would like for it to choose itself what application to use
but the only hint I was able to find was to change it to something like this

Code: Select all

#!/bin/sh

FILE=`Xdialog --title "Whats Next!" --fselect / 28 58 2>&1`

case $? in
   0)
if [ "${FILE##*.}" = "mp3" ]
then
      xmms "$FILE" ;;
elif  [ "${FILE##*.}" = "avi" ]
then
      gxine "$FILE"
elif
   1)
      echo "Cancel pressed.";;
   255)
      echo "Box closed.";;
esac 
there's gotta be a better way to test the extension so I could
only have to define the application once something like this

if [ "${FILE##*.}" = "mp3" or "wav" or "ogg"]

I know this is not a puppy question but help would be greatly apperciated :?

User avatar
Dougal
Posts: 2502
Joined: Wed 19 Oct 2005, 13:06
Location: Hell more grotesque than any medieval woodcut

#2 Post by Dougal »

Code: Select all

case $? in
   0)
     case "$FILE" in
      *.mp3) xmms "$FILE" ;;
      *.avi) gxine "$FILE" ;;
     esac
     ;;
   1)
      echo "Cancel pressed.";;
   255)
      echo "Box closed.";;
esac 
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#3 Post by MU »

Code: Select all

a="test.wav"


check=`echo "$a" | sed "s/.*\(mp3\|wav\|ogg\)$/MUSIC/"`

if [ "$check" == "MUSIC" ];then
  xmms "$a"
  exit 0;
fi

check=`echo "$a" | sed "s/.*\(wmv\|avi\|mpg\)$/VIDEO/"`


if [ "$check" == "VIDEO" ];then
  mplayer "$a"
  exit 0;
fi

Mark

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#4 Post by GuestToo »

this should open a file exactly as if you clicked the file in a Rox window ... that is, Rox will open the file with whatever Run Action has been configured in Rox (for example a text file, might open with Geany or Leafpad, a music file might open with Gxine or Xmms ... whatever the Run Action is set to:

rox "$FILE"

it opens it as a background process, so you don't need to end the command line with a &

User avatar
willhunt
Posts: 495
Joined: Wed 05 Oct 2005, 18:19

#5 Post by willhunt »

Thank you all for your help :)
I tried all the soloutions they were all great I could not get the sed command to work the first timde but that is the one I will use as it makes the smallest file without haveing to change the default prg for the file

Post Reply