#!/bin/sh # @(#) Hide/show a GUI app #..# systems: #..# sites: #..# level: #..# keys: #..# date: Fri Mar 26 09:01:21 GMT 2004 #..# vers: 1.2 26/Mar/2004-10:48 [ $0 = ${0#/} ] && this=$(pwd)/$0 || this=$0 tag=${0##*/} #tm=/tmp/${tag} #tmp=${tm}$$ #rm -f ${tm}* #set -A AWK $(whence nawk) #[ ${#AWK[*]} -gt 0 -a "${AWK[0]}" != no ] && alias awk=${AWK[0]} # Set up mode depending on how called # Generic approach allowed by 'ksh' # set -A calls hideapp showapp # set -A modes false true # typeset -i i=0 # while [ $i -lt ${#calls[*]} ]; do # [ "$tag" = "${calls[$i]}" ] && { mode=${modes[$i]}; break; } # i=$(($i + 1)) # done # Fixed version needed for 'bash' calls="hideapp showapp" [ "$tag" = hideapp ] && mode=false || mode=true usage="Usage: $tag [-hide|-show] " while [ $# -gt 0 ]; do case "$1" in -v|-x) set "$1" ;; -vi) vi $this; exit ;; -view) view $this; exit ;; -about) echo "$tag was written by David Ledger" echo "dledger at ivdcs.co.uk" echo "Free to use at your own risk" echo "Copyright 2004" exit ;; -ver) ver=$(egrep '#..#[ ]*vers:' $this) ver=${ver#"${ver%%[1-9]*}"} print ${ver%%[!0-9.]*} exit ;; -h) echo "" echo "$usage" echo "" echo "$tag calls an AppleScript to show or hide an application" echo "similar to H. It has two names, ${calls[*]}" echo "to hide or show the named application. Either may be" echo "given a '-hide' or '-show' flag to override the named" echo "functionality." echo "" echo "Only one application may be specified as application" echo "names may have embedded spaces. Applications with any" echo "number of single spaces will work. Any application with" echo "a name containing a run of spaces or other special" echo "characters will need appropriate quoting." echo "" echo "To install, copy into a directory on your PATH and run:" echo " $tag -install" echo "which will create the link to the other command name." echo "" exit ;; -install) # for call in ${calls[*]}; do # ksh for call in $calls; do # bash [ $call = $tag ] && continue cd ${this%/*} || exi rm -if $call [ -f $call ] || ln $tag $call done exit ;; -show) mode=true ;; -hide) mode=false ;; --) ;; -*) opt="$1" shift set -- -- $(getopt hvx $opt) $@ || exit ;; *) app="$*" break ;; esac shift done [ "$app" ] || { print -u2 "$usage" print -u2 "${tag}: No application specified" exit 1; } osascript -e 'tell application "Finder"' \ -e 'if exists application process "'"$app"'" then set visible of application process "'"$app"'" to '"$mode" \ -e 'end tell'