Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Slightly more refined version' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Slightly more refined version
Authored by: jecwobble on Nov 25, '04 09:39:20AM
In case anyone is interested in using this script (turns out I use it everyday since I don't care for the fortunes that the original hint produces), here's a slightly more refined version that removes unused code and adds a little more user friendliness to the UI:
#! /bin/sh

####### Define constants and Variables #######

ME=`basename $0`       # Capture this script's name
VERS="1.0"             # Current version number
E_NOLENGTH=66          # Exit code for zero length arguments


####### UI Information #######

usage () {
   echo
   echo "  Usage: $ME [options] string"
   echo "  Script for manipulating the logon window's banner"
   echo "  Options:"
   # Change the following as needed
   # and mirror in the following section
   echo "        -b         List current banner text"
   echo "        -l         Go to login window to view results"
   echo "        -u         Unset login window banner. Other options ignored"
   echo "        -h         For this help list"
   echo
}

bannerNotSet() {
   echo "  Login window banner is not set."
   echo
   exit 0
}

####### Parse command line #######

# Get options from $@ (parameters/arguments"
while getopts bluh option
do
   case $option in
   b)   OPT_b=1;;
   l)   OPT_l=1;;
   u)   OPT_u=1;;
   h)   usage
        exit 0;;
   esac
done

# This strips off options leaving remaining parameters
shift $(($OPTIND - 1))


##############################################################
#                     Main script area                       #
#      If we got this far, all command line parameters       #
#                        must be good                        #
##############################################################

# Unset login window banner
if [ -n "$OPT_u" ]; then
   /usr/bin/defaults delete /Library/Preferences/com.apple.loginwindow LoginwindowText 2> /dev/null
   echo
   echo "  Deleted login window banner"
   echo
   exit 0
fi

# Assign text to banner
if [ -n "$OPT_b" ]; then
   echo
   /usr/bin/defaults read /Library/Preferences/com.apple.loginwindow LoginwindowText 2> /dev/null || bannerNotSet
   echo
   exit 0
fi

# Assign text to banner
if [ -z "$1" ]; then
   echo
   echo "  $ME error: No empty string arguments allowed" >&2
   usage >&2
   exit $E_NOLENGTH
else
   /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText -string "$1"
   echo
   echo " Login window banner set"
   echo
fi

# Preview banner
if [ -n "$OPT_l" ]; then
   /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
fi


######## Exit with a successful code ########
exit 0


[ Reply to This | # ]