#!/bin/sh # # Font Cleanup script v.1.1 # # This will revert a user's font set to the 10.4 default list # # Author: Eddie Kelley # # ////////////////////////////////////////////////////////////////////// # # We need to do each section of Fonts separately (System vs. Library) # the default list of fonts should be in files next to this script # and should be named 10.X_SystemFonts.txt and 10.X_LibraryFonts.txt, # where X is the minor version of the system - # otherwise, the paths for each list should be changed below # # Default fonts lists located here: # # 10.3: http://docs.info.apple.com/article.html?artnum=25710 # 10.4: http://docs.info.apple.com/article.html?artnum=301332 # 10.5: http://docs.info.apple.com/article.html?artnum=307069 # # ////////////////////////////////////////////////////////////////////// # # Version History: # Dec. 5th, 2007 v.1.0 Created script to assist with Font cleanup/organization # Dec. 13th, 2007 v.1.1 Modified script to work with 10.3-10.5 systems # # get the running system version so that we can decide which lists to use OS_VERSION="`defaults read /System/Library/CoreServices/SystemVersion ProductVersion`" # get local variables, such as the user's name, their home directory, and their UID USER_UID="`id -u`" USER_NAME="`id -un`" USER_HOME="`dscl . -read /users/$USER_NAME NFSHomeDirectory | sed s/NFSHomeDirectory:.//`" # specify the location of the System, Library, and User font folders SYSTEM_FONTS="/System/Library/Fonts" LIBRARY_FONTS="/Library/Fonts" USER_FONTS="$USER_HOME/Library/Fonts" # specify the location that non-default fonts will be moved OLD_SYSTEM_FONTS="/System/Library/Fonts.old" OLD_LIBRARY_FONTS="/Library/Fonts.old" OLD_USER_FONTS="$USER_HOME/$LIBRARY_FONTS.old" # specify the font cache locations FONT_CACHES="/Library/Caches" USER_FONT_CACHE="$FONT_CACHES/$USER_UID" # set_font_lists will specify which font list to use based on system software version (10.3-10.5) set_font_lists(){ case $OS_VERSION in 10.5*) LIBRARY_LIST="./10.5_LibraryFonts.txt" SYSTEM_LIST="./10.5_SystemFonts.txt" shift;; 10.4*) LIBRARY_LIST="./10.4_LibraryFonts.txt" SYSTEM_LIST="./10.4_SystemFonts.txt" shift;; 10.3*) LIBRARY_LIST="./10.3_LibraryFonts.txt" SYSTEM_LIST="./10.3_SystemFonts.txt" shift;; *) echo "Operating system version $OS_VERSION is not supported." exit;; esac } # revert_system_fonts will revert the /System/Library/Fonts folder back to defaults based on the current system revert_system_fonts(){ if [ -e $SYSTEM_LIST ]; then # First, move the /System/Library/Fonts folder aside, and create a new one if [ -d $OLD_SYSTEM_FONTS ]; then sudo mv $SYSTEM_FONTS/* $OLD_SYSTEM_FONTS else sudo mv "$SYSTEM_FONTS" "$OLD_SYSTEM_FONTS" sudo mkdir "$SYSTEM_FONTS" sudo chown root:wheel "$SYSTEM_FONTS" sudo chmod 755 "$SYSTEM_FONTS" fi # Read in each line from the System Fonts list, and move each occurrence back into place cat $SYSTEM_LIST | while read FONT do sudo mv "$OLD_SYSTEM_FONTS/$FONT" "$SYSTEM_FONTS/$FONT" done else echo "ERROR: Could not find System Font list - continuing without moving System fonts" fi } # revert_library_fonts will revert the /Library/Fonts folder back to defaults based on the current system. revert_library_fonts(){ if [ -e $LIBRARY_LIST ]; then # Move the /Library/Fonts folder aside, and make sure to apply correct permissions if [ -d "$OLD_LIBRARY_FONTS" ]; then sudo mv "$LIBRARY_FONTS"/* "$OLD_LIBRARY_FONTS" else sudo mv "$LIBRARY_FONTS" "$OLD_LIBRARY_FONTS" sudo mkdir "$LIBRARY_FONTS" sudo chown root:admin "$LIBRARY_FONTS" sudo chmod 775 "$LIBRARY_FONTS" fi # Read in each line from the Library Fonts list, and move each occurrence back into place cat $LIBRARY_LIST | while read FONT do sudo mv "$OLD_LIBRARY_FONTS/$FONT" "$LIBRARY_FONTS/$FONT" done else echo "ERROR: Could not find Library Font list - continuing without moving Library fonts" fi } # revert_user_fonts will revert the ~/Library/Fonts folder back to defaults (0 fonts) revert_user_fonts(){ if [ -d "$OLD_USER_FONTS" ]; then mv "$USER_FONTS"/* "$OLD_USER_FONTS" else mkdir -p "$OLD_USER_FONTS" mv "$USER_FONTS"/* "$OLD_USER_FONTS" fi } clean_font_cache(){ sudo rm -rf "$FONT_CACHES" } # Provide user with instructions clear echo "FontCleanup v.1.1" echo "" echo "Author: Eddie Kelley " echo "" echo "This script will reset the /Library/Fonts, /System/Library/Fonts, and ~/Library/Fonts folders" echo "back to the default font sets based on the operating system installed. The script is compatible" echo "with Mac OS X v.10.3.x - 10.5.x." echo "" echo "Third-party fonts will be moved into folders called "Fonts.old" within each modified folder (Library, System/Library, and ~/Library)" echo "" echo "Please enter your administrative password to proceed..." # Change directories into the cwd cd "`dirname "$0"`" # First, set the location of the default fonts lists # to the list for the current system version - if the system is unknown, exit set_font_lists # Next, copy all fonts from that folder that belong in /System/Library/Fonts back revert_system_fonts # Then, copy all fonts from that folder that belong in /Library/Fonts back revert_library_fonts # The user's Fonts folder is empty by default - Make it so. revert_user_fonts # we should cleanup the font caches after performing this operation clean_font_cache # This may require a logout - mention it to the user echo "FontCleanup script finshed - PLEASE LOG OUT OR RESTART TO REBUILD FONT CACHES"