#!/bin/sh

cmd=$1
file=$2
volume=$2

open() {
  osascript << EOF
tell application "QuickTime Player"
  activate
  set show welcome movie automatically to false
  open POSIX file "$file"
  present movie 1 scale screen
  play front movie
end tell
EOF
}

close() {
  osascript << EOF
tell application "QuickTime Player"
   close every movie
end tell
EOF
}

volup() {
  vol=$(osascript -e 'set curVolume to output volume of (get volume settings)')
  newvol=$(( vol + 10 ))
  echo "Vol from $vol to $newvol"
  osascript -e "set volume output volume $newvol"
}

voldown() {
  vol=$(osascript -e 'set curVolume to output volume of (get volume settings)')
  newvol=$(( vol - 10 ))
  echo "Vol from $vol to $newvol"
  osascript -e "set volume output volume $newvol"
}

vol() {
  osascript -e "set volume output volume $volume" 
}

case "$cmd" in
  'open')
    open;
    ;;
  'close')
    close;
    ;;
  'vol')
    vol;
    ;;
  'volup')
    volup;
    ;;
  'voldown')
    voldown;
    ;;
  *)
    echo "$0 <command> <parameter>"
    echo "  with command:"
    echo "    open <complete path to movie file>"
    echo "    close"
    echo "    vol <vol as integer between 0 and 100>"
    echo "    volup"
    echo "    voldown"
    ;;
esac

