#!/bin/bash
export QT_MAC_DISABLE_FOREGROUND_APPLICATION_TRANSFORM YES
#LOG=/dev/null
LOG=~/.mcf/tmp/AutoBookService.log


APP="AUTOBOOKSERVICE"
BID="BUNDLEIDENTIFIER"

if test -f "$APP"
then
    "$APP"           >> $LOG  2>&1
    exec 1>&0
    exec 2>&0
    date             >> $LOG  2>&1 
    echo "Ende: $?"  >> $LOG  2>&1
    exit
fi




FOUND=`mdfind "kMDItemCFBundleIdentifier == $BID" | while read  line; do stat -f "%m %N" "$line"; done | sort -n  | tail -1 | cut -c 12-` 

APP="$FOUND/Contents/Helpers/AutoBookService"


if test -f "$APP"
then
    "$APP"           >> $LOG  2>&1
    date             >> $LOG  2>&1 
    echo "Ende: $?"  >> $LOG  2>&1
fi    

date                              >> $LOG  2>&1 
echo "No AutoBookService found"   >> $LOG  2>&1 
exit




