#!/bin/bash #=========================================================================== # File playlast.sh # Checks if files exist, and if so plays last compiled 12 note tune # generated by serialrpi.sh or serialr.sh # usage ./playlast.sh pi OR .playlast.sh mac # Can be run in LXDE terminal or from a remote ssh connection # Option pibrowser TRUE runs on pi desktop FALSE runs output on Mac # is set by input argument pi or mac # Option quitbrowser FALSE or TRUE to control whether browser is shut at the end # Check Mac configuration options before running with playlast.sh mac # Written by Robin Newman, Aug 2013 #=========================================================================== #pibrowser set TRUE to run on pi desktop browser, FALSE to run on external Mac #now set by argument on command line prefbrowser=midori #select midori or netsurf (for pi playback) quitbrowser=TRUE #forces browser to quit at end of script TRUE/FALSE pishare='/home/pi/pishare' #where share is mounted on the Pi macssh="rbn@192.168.1.12" #ssh logon to the Mac macbrowserapp="Firefox.app" #Browser to run on Mac (could be Safari.app,Google Chrome.app) macpathtoshare='/Users/rbn/Documents/pishare' #path to share on the Mac #you shouldn't need to configure anything after this line macbrowser=`echo $macbrowserapp | cut -d'.' -f1` #strips the .app from macbrowserapp #parse input argument and set pibrowser accordingly if [[ -z $1 || $1 != 'pi' && $1 != 'mac' ]] then echo "usage ./playlast.sh pi or ./playlast.sh mac" exit 1 fi if [ $1 = 'mac' ]; then pibrowser=FALSE;else pibrowser=TRUE;fi if [ $pibrowser = TRUE ] then web=/tmp/tonerow.html midifile=/tmp/tonerow.midi #check if Desktop is running if [[ `pidof lxsession` = "" ]] then echo 'no desktop running on the Pi.startx & from this terminal, then rerun' exit else export DISPLAY=:0 fi if [ -f $web ] #check if webpage exists then if [ "$(pidof $prefbrowser)" ] #first kill existing browser if running then killall $prefbrowser fi echo Starting Web Browser if [ $prefbrowser = midori ] then $prefbrowser -e Fullscreen -a $web & else $prefbrowser file://$web & fi sleep 4 #allow time for web browser to open echo Playing midi file sleep 2 timidity $midifile &> /dev/null #play midi file #wait before killing browser sleep 2 if [ $quitbrowser = TRUE ] #then force browser to quit then killall $prefbrowser echo browser killed fi else echo "No $web so can't run" fi else if [ -f $pishare'/tonerow/tonerow.html' ] #check if html exists then #(re)copy quit.sh script to mac cp quit.sh $pishare/tonerow open firefox with html page by ssh to mac cmd='ssh '$macssh' " open -a /Applications/'$macbrowserapp'/ ' cmd+='file://'$macpathtoshare'/tonerow/tonerow.html"' eval $cmd #wait for tune to play sleep 20 if [ $quitbrowser = TRUE ] #then force browser to quit then echo 'close mac browser' #use quit.sh script in tonerow folder to close Firefox again #this script is obtainable at http://mattdturner.com/resources/quit cmd='ssh '$macssh' "sh '$macpathtoshare'/tonerow/quit.sh ' cmd+=$macbrowser' &>/dev/null"' eval $cmd fi else echo "No web page on mac so can't run" fi fi echo "Finished!" #------------ end of script -------------