3

I control XBMC with a simple remote (this one) which is detected as generic keyboard. Is it possible to define a shortcut that starts/stops XBMC when I press a button?

I am using my Raspberry Pi mainly as a media player, but I would also like to run Transmission and other services simultaneously. Unfortunately, XBMC and Transmission don't get along very well because XBMC takes a lot of resources. So I thought that I could make a small script that stops XBMC when it is not being used and starts Transmission (I think that XBMC has an API that I can use to do that...). The problem is that I need simple way to restart XBMC and stop Transmission - ie, I don't want to use SSH every time I want to watch a movie.

1

This script detects if a program is running or not and launches/stops its executable accordingly. I've found it here and I've simply cleaned it a bit. You can easily test it (as I did because I don't have a Pi right now) simply uncommenting the two lines with gcalctool.

If you copy and adapt this script to launch transmission and wrap the two together, you can have the script you're asking for.

#!/bin/bash

PROGRAMBIN="xbmc.bin"
#PROGRAMBIN="gcalctool"
PROGRAMWRAPPERSCRIPT="xbmc"
#PROGRAMWRAPPERSCRIPT="gcalctool"
PIDOFPROGRAMBINCMD="pidof $PROGRAMBIN"
PIDOFPROGRAMBIN=`eval $PIDOFPROGRAMBINCMD`
STOPDELAY=2
PROGRAMSTR="XBMC"

if [ "x$PIDOFPROGRAMBIN" != "x" ] ; then
        # Try a clean kill
        echo "Closing $PROGRAMSTR"
        kill $PIDOFPROGRAMBIN

        # takes a second or two to die with the soft kill
        sleep $STOPDELAY

        PIDOFPROGRAMBIN=`eval $PIDOFPROGRAMBINCMD`
        if [ "x$PIDOFPROGRAMBIN" != "x" ] ; then
                kill -9 $PIDOFPROGRAMBIN
                echo "$PROGRAMSTR stopped (hard)"
        else 
                echo "$PROGRAMSTR stopped (soft)"
        fi  
else
        echo "Starting $PROGRAMSTR..."
        eval $PROGRAMWRAPPERSCRIPT &
fi

echo "Done"

The problem is to have such a script paired with a keyboard shortcut. Normally, one would have defined a keyboard shortcut inside lightdm. But I think that XBMC takes over any keyboard input, so I suppose you'll have to hook the script both to XBMC and to lightdm.

  • Thanks for the answer. I am using raspbmc so I don't have lightdm installed. Do you know if it possible to define a keyboard shortcut without X? – nmat Oct 22 '12 at 14:01
  • No, sorry I have no brilliant ideas in this sense. As far as I can tell, whenever XBMC exits, it drops you into a shell, right? Maybe you could try to run an infinite loop like this to intercept keypresses and launch the killer/launcher script in background. A really ugly solution, I know, but I haven't been able to come out with a better idea... – Avio Oct 22 '12 at 14:50
0

I just built a very simple script to start xbmc when enter is pressed on a keyboard attached to the pi.

#!/bin/bash

while true
do
  echo
  echo -n Press Enter to start XBMC.
  read
  echo Starting XBMC...
  /usr/bin/sudo -u xbmc /usr/bin/xbmc-standalone
done

The line with "read" can be modified to fire on single key presses and you'll need to add a little more logic to differentiate which key is pressed and run an application based on that.

The tricky part is how to make the pi run the script on startup. I modified this line from /etc/inittab (I'm running raspbian):

1:2345:respawn:/sbin/getty --noclear 38400 tty1

to read:

1:2345:respawn:/root/xbmc-starter.sh

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.