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


Click here to return to the 'A generic script to change the login banner' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A generic script to change the login banner
Authored by: jecwobble on Nov 18, '04 11:20:27PM
For the fun of it (and the practice), I decided to wrap part of this hint up into a script. I called it loginbanner (only because banner is already taken), and saved it in ~/bin. Pretty straight forward. I haven't tested it extensively, so it may choke in unusual situations.

#! /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 "  Change the logon window's banner"
   echo "  Options:"
   # Change the following as needed
   # and mirror in the following section
   echo "        -c         Center text"
   echo "        -l         Go to login windoi to view results"
   echo "        -u         Unset login window banner. Other options ignored"
   echo "        -h         For this help list"
   echo
}

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

# Get options from $@ (parameters/arguments"
while getopts cluh option
do
   case $option in
   c)   OPT_c=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))

# Check for zero length arguments
# Uncomment to activate
for arg in "$@"
do
   if [ -z "$arg" ]; then
      echo
      echo "$ME error: No empty string arguments allowed" >&2
      usage >&2
      exit $E_NOLENGTH
   fi
done


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

# Unset login window banner
if [ ! -z "$OPT_u" ]; then
   echo "Deleting login window text"
   /usr/bin/defaults delete /Library/Preferences/com.apple.loginwindow LoginwindowText
   exit 0
fi

# Center text
if [ ! -z "$OPT_c" ]; then
   echo "Trying to center"
fi

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

# Preview banner
if [ ! -z "$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 | # ]
Ignore the centered text part...
Authored by: jecwobble on Nov 19, '04 08:37:25AM

I had planned to include script for centering the text based on a fixed character width, but abandoned the idea when I realized that the font that appears in the login window is not mono-spaced. If it had been, I was going to search for a script I remembered seeing somewhere that would pad some text with spaces to center it within a given number of columns.



[ Reply to This | # ]
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 | # ]