Register
It is currently Tue Jul 29, 2014 2:54 pm

Open foo on tv screen


All times are UTC - 6 hours


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 PostPosted: Sun Sep 06, 2009 11:55 am   

Joined: Sun Sep 06, 2009 11:47 am
Posts: 4
I want to right click on a file and send it to DISPLAY=:0.1

Now I have a different script for every thing like one for avi(eg. DISPLAY=:0.1 totem), one for pictures (eg. DISPLAY=:0.1 eog).

I wonder if it is possible to have one script to do this: OPEN on display 0.1. and how do I put them together?

thanks


Top
 Profile  
 PostPosted: Sun Sep 06, 2009 1:26 pm   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
What distro and window manager are you using? I'll assume a standard gnome setup.

I'm not sure what you've finished already, but in case you don't know this already, any script that you put in ~/.gnome2/nautilus-scripts/ will show up in the right-click menu if it is executable (chmod u+x filename for the unknowing).

If you want to use one script for all of the different file types, you'll need to detect what type of file you are working with to select the correct application to call. There are a few ways to do this:

1. Do a regex match against the filename.
2. (Recommended) Do a regex match against the output of 'file -b filename'
3. There is probably a cleaner way to do this that I don't know about.

You can set the display variable at the top of your script with DISPLAY=:0.1
For option 2, you might do:
Code:
#!/bin/bash
DISPLAY=:0.1
output=`file -b $1`
if [[ "$output" =~ 'AVI' ]]; then
  totem $1
elif [[ ... ]]; then
   ...
fi


I don't know what the ouput of file is for the different types that you want, so you'll need to test them out and construct your regexes accordingly.

- thobbs


Top
 Profile  
 PostPosted: Sun Sep 06, 2009 3:47 pm   

Joined: Sun Sep 06, 2009 11:47 am
Posts: 4
Thanks for the quick reply.

Yes I am using an default Ubuntu 9.04 with gnome.

I was putting every file separately in the nautulus script folder but it resulted in 5-10 different scripts to choose from.

All scripts I made consisted of only the following:

Display=:0.1 eog

I am new at scripting but I am trying to learn.

Your input is very helpfull, I didn't know how to use the IF command. But You helped me to get started. I will post the final result tomorrow.


Top
 Profile  
 PostPosted: Mon Sep 07, 2009 2:00 am   

Joined: Sun Sep 06, 2009 11:47 am
Posts: 4
Hello, I tried the script and it's not working as I would like.

The problem is spaces in between filenames. eg. "Adventureland.avi" is no problem but "District 9.avi" doesn't show.

DISPLAY=:0.1
output=`file -b $1`
if [[ "$output" =~ 'AVI' ]]; then
totem --fullscreen $1

Can it be solved bij putting brackets some where?

I tried
output=`file -b "$1"`

Totem will come up saying "location not found".


Top
 Profile  
 PostPosted: Mon Sep 07, 2009 6:15 pm   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
Oops, yeah, I missed that. You should surround $1 with double quotes both times that it is used. i.e.
Code:
DISPLAY=:0.1
output=`file -b "$1"`
if [[ "$output" =~ 'AVI' ]]; then
  totem --fullscreen "$1"
...

It's always a good idea to surround these types of things with double quotes ... I don't know why I forgot!

- thobbs


Top
 Profile  
 PostPosted: Tue Sep 08, 2009 4:18 pm   

Joined: Sun Sep 06, 2009 11:47 am
Posts: 4
Thanks, that solved it..


Top
 Profile  
 PostPosted: Mon Oct 05, 2009 9:17 pm   

Joined: Mon Oct 05, 2009 6:31 pm
Posts: 6
This is actually one of the first scripts that I ever wrote. It's purpose was to have a single command that could display several types of media using various apps that could be user specified. Your situation brought it to mind, so I figured I would post it here in the hopes it would give you some ideas. It would have to be slightly modified in how it called the viewer apps to suit your purposes, but not a major operation. Hope it helps...

Code:
#!/bin/sh
#
# (Hopefully) plays all specified files as filtered with regular expression from a directory using chosen media player (?)
#
# Expected Usage:
# mplay regexp
# regexp represents the location and types of files to play (expected media extensions) i.e /mnt/cdrom/movies/*.mpg
#
AlarmCatcher() {
clear
echo -e "Timeout... \c"
KillSubs
TIMERPROC=
}
KillSubs() {
echo -e "SUBS KILL: \c"
if [ -n "$CHILDPROC" ]; then
  kill $CHILDPROC > /dev/null
  if [ $? -eq 0 ]; then
   echo "ok"
  else
   echo "failed"
  fi
  CHILDPROC=
else
  echo "no subs to kill..."
fi
}
SetTimer() {
if [ -z "$TIMEOUT" ]; then
  TIMEOUT=10
fi
if [ $TIMEOUT -ne 0 ]; then
  sleep $TIMEOUT && kill -s 14 $$ &
  CHILDPROC="$CHILDPROC"
  TIMERPROC="$!"
fi
}
UnsetTimer() {
echo -e "STOP TIMERS: \c"
if [ -n "$TIMERPROC" ]; then
  kill $TIMERPROC > /dev/null
  if [ $? -eq 0 ]; then
   echo "ok"
  else
   echo "failed"
  fi
  TIMERPROC=
else
  echo "no active timers..."
fi
}
CleanUp() {
KillSubs
UnsetTimer
exit
}

echo "                    MEDIA PLAYER SCRIPT"
echo "Select the Media Player to use to play/view the specified $# files:"
select CHOICE1 in MPlayer Aviplay Xine GTV XMMS Eye_of_Gnome Electric_Eyes Cancel
do
case $CHOICE1 in
  MPlayer)  PLAYER="`which mplayer` -fs" ; break ;;
  Aviplay)  PLAYER="`which aviplay`" ; break ;;
  Xine)  PLAYER="`which xine` -hpq" ; break ;;
  GTV)  PLAYER="`which gtv`" ; break ;;
  XMMS)  PLAYER="`which xmms`" ; break ;;
  Eye_of_Gnome)  PLAYER="`which eog`" ; break ;;
  Electric_Eyes)  PLAYER="`which ee`" ; break ;;
  Cancel) exit ;;
  *) echo "Invalid option, $CHOICE1"
esac
done
SLIDESHOW=
echo "Do you want a timed SlideShow of specified files?"
select CHOICE2 in Yes No Cancel
do
case $CHOICE2 in
  Yes) 
   SLIDESHOW="true"
   echo -e "Enter the number of seconds for each file to display (default 10): \c"
   read TIMEOUT ; break
  ;;
  No)  break ;;
  Cancel) exit ;;
  *) echo "Invalid option, $CHOICE2"
esac
done

# main ()

trap CleanUp 1 2 3  9 15
trap AlarmCatcher 14
FILECNT=0
for NXT_FILE in "$@" ; do
if [ -n "$SLIDESHOW" ]; then
  SetTimer
fi
if [ -f "$NXT_FILE" ]; then
  FILECNT=$(( $FILECNT + 1 ))
  echo "Displaying file $FILECNT of $# - `basename $NXT_FILE`"
  ${PLAYER} ${NXT_FILE} &
  if [ -n "$SLIDESHOW" ]; then
   CHILDPROC="$CHILDPROC $!"
   wait $!
   UnsetTimer
  else
   wait $!
  fi
else
  echo "The indicated file `basename $NXT_FILE` doesn't exist, isn't accessible or isn't a file...skipping"
  continue
fi
done
echo "No more files...exiting"
exit 0


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP