While we're on the topic of linux scripts, I'm wondering if you or anyone can see what's wrong with a script I was working on this morning (I'm making my first attempt at using xbmc and advanced launcher with linux this past week).
I'm using a pair of dual shock 3 controllers through bluetooth on ubuntu 10.04. A lot of emulators don't allow you to bind a joystick button for exiting, so I'm using joy2key (no relation to the windows program, I think) in the scripts to map the home button to the relevant keyboard key. I'm also using it to control evince, the default gnome document viewer, for looking at manuals/guides. My problem with the script is that joy2key, when launched, looks for the program included as an argument and if it's started too soon after the emulator/evince then it will fail and not map anything.
What I'm using that works (where path.to.doc and docname.ext refer to some arbitrary document) is:
Quote:#!/bin/bash
killall -STOP xbmc.bin
evince --presentation "path.to.doc" & sleep 5 && joy2key "docname.ext" -config evince
wait
killall -CONT xbmc.bin
My only problem is that the fixed 5 second pause isn't ideal. I had it at 3 seconds initially, but it failed a couple times (I think only when loading cbz/cbr files which makes some sense). Ideally though, I'd like a solution that keeps the delay in starting joy2key to a minimum and that I know with near absolutely certainty will map the keys as desired.
Earlier today, I thought I'd gotten it working with:
Quote:#!/bin/bash
killall -STOP xbmc.bin
EXITSTATUS=-1
evince --presentation "path.to.doc" & until $EXITSTATUS == 0 (wiki); do
sleep 1
joy2key "docname.ext" -config evince
EXITSTATUS=$?
done
wait
killall -CONT xbmc.bin
(I've also tried the above both with and without the wait command.)
What it's supposed to do is keep trying to run joy2key, once a second, until the exitcode for joy2key is returned as 0 (meaning it found the indicated window). It actually worked fine when launched as a standalone file and even if I open XBMC, but run the script independently, it pauses and resumes XBMC just fine.
If I launch it from within advanced launcher, it loads the document/game and joy2key correctly maps the button(s) (immediately). Unfortunately, after exiting the emulator/evince, it never resumes XBMC. Even more, if I manually resume XBMC (with killall -CONT) and select another game/document, it freezes on a black screen, doesn't respond to any input and requires a hard reboot.
Potentially worth noting is that because I need to use different programs for files under the same file launcher (either to use different emulators for different games, or to use the document viewer for a game's manual/guide), I'm using the following dummy launcher. With the above error, the process for this script doesn't appear to close even after joy2key and the document/emulator do:
Quote:#!/bin/bash
sh "$1"
wait
Sorry for being so long winded. Figuring this out isn't especially important, but I'm pretty much clueless here and only put together the above by with google. What's really throwing me off is that it works fine if launched from outside xbmc and doesn't from within. If looking at it, you think you know the problem, I'd appreciate the feedback.
Also, I've proofread this post several times, but I keep coming across sentences that just don't make any sense. I'm just about asleep already, so sorry if there's still some gibberish mixed in.