#!/bin/sh

# open2 - Enveloppant astucieux pour exploiter encore mieux
#   la commande Mac OS X trs sympa open. 
# 
# Par dfaut, open appelle l'application approprie pour un fichier ou
# un rpertoire donn en se fondant sur les rglages d'Aqua; elle est
# aussi capable d'appeler des applications se trouvant dans le
# rpertoire /Applications

# Quel que soit l'argument fourni, on l'essaie d'abord directement: 

open="/usr/bin/open"

if ! $open "$@" >/dev/null 2>&1 ; then
  if ! $open -a "$@" >/dev/null 2>&1 ; then

    # Plusieurs arguments? Je ne sais pas quoi en faire; on quitte
    if [ $# -gt 1 ] ; then
      echo "$0: je ne sais pas comment ouvrir ou appeler $@" >&2
      exit 1
    else
      case $(echo $1 | tr '[:upper:]' '[:lower:]') in
        acrobat      ) app="Acrobat Reader"             ;;
        adress*      ) app="Address Book"               ;;
        chat         ) app="iChat"                      ;;
        cpu          ) app="CPU Monitor"                ;;
        dvd          ) app="DVD Player"                 ;;
        excel        ) app="Microsoft Excel"            ;;
        netinfo      ) app="NetInfo Manager"            ;;
        prefs        ) app="System Preferences"         ;;
        print        ) app="Print Center"               ;;
        profil*      ) app="Apple System Profiler"      ;;
        qt|quicktime ) app="QuickTime Player"           ;;
        sync         ) app="iSync"                      ;;
        word         ) app="Microsoft Word"             ;;
        * ) echo "$0: je ne sais pas quoi faire de $1" >&2
            exit 1
      esac
      echo "Vous avez demand $1 mais j'ai interprt $app." >&2
      $open -a "$app"
    fi
  fi
fi

exit 0
