Last active
April 30, 2019 21:46
-
-
Save MikeWilkie/5331d8b1a1a0fb457733518d0ccb2971 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# ===================================================== | |
# * macOS Maintenance Script * | |
# * Written by Kristan M. Kenney (iCeFuSiOn) * | |
# * Modified by Mike Wilkie (github.com/MikeWilkie) * | |
# * Last modified on May 1, 2018 06:05:18 PM EST * | |
# * Revision 1.0.1c * | |
# * For use on macOS 10.13 High Sierra Only! * | |
# * I AM NOT RESPONSIBLE IF YOU DO SOMETHING WRONG! * | |
# ===================================================== | |
# To install: | |
# add to ~/Scripts/ | |
# add "alias maintain='~/Scripts/maintenance.sh'" to ~/.bash_profile | |
clear | |
echo "Mac OS X 10.13 Maintenance Script" | |
echo "WARNING: Close any running applications before continuing." | |
echo "" | |
echo -n "Would you like to proceed? (y/N): "; read PROCEED | |
if [ -z $PROCEED ] || [ "$PROCEED" = "n" ] || [ "$PROCEED" = "N" ]; then | |
exit 0 | |
fi | |
echo "" | |
echo -n "Run maintenance cron scripts (daily, weekly, and monthly)? (Y/n): "; read CRONSCR | |
if [ -z $CRONSCR ] || [ "$CRONSCR" = "y" ] || [ "$CRONSCR" = "Y" ]; then | |
sudo periodic daily weekly monthly | |
echo "Maintenance scripts have run successfully." | |
echo "" | |
fi | |
echo "" | |
echo -n "Flush user cache and log entries? (Y/n): "; read USRLOG | |
if [ -z $USRLOG ] || [ "$USRLOG" = "y" ] || [ "$USRLOG" = "Y" ]; then | |
echo "Flushing saved logs under current users Home directory ..." | |
cd ~/Library/Logs | |
sudo rm -rf ~/Library/Logs/* | |
echo "Flushing user cache ..." | |
rm -rf ~/Library/Safari/Downloads.plist | |
cd ~/Library/Caches | |
sudo rm -rf ~/Library/Caches/* | |
fi | |
echo "" | |
echo -n "Flush global cache? (Y/n): "; read GLOBAL_CACHE | |
if [ -z $GLOBAL_CACHE ] || [ "$GLOBAL_CACHE" = "y" ] || [ "$GLOBAL_CACHE" = "Y" ]; then | |
echo "Flushing global cache ..." | |
cd /Library/Caches | |
sudo rm -rf /Library/Caches/* | |
fi | |
echo "" | |
echo -n "Flush Directory Service cache? (Y/n): "; read DSERVCACHE | |
if [ -z $DSERVCACHE ] || [ "$DSERVCACHE" = "y" ] || [ "$DSERVCACHE" = "Y" ]; then | |
echo "Flushing Directory Service resolver cache ..." | |
dscacheutil -flushcache | |
fi | |
echo "" | |
echo -n "Flush LaunchServices database (fixes duplicate Open With entries, etc) (Y/n):"; read LS_DATABASE | |
if [ -z $LS_DATABASE ] || [ "$LS_DATABASE" = "y" ] || [ "$LS_DATABASE" = "Y" ]; then | |
echo "Flushing LaunchServices database ..." | |
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user | |
fi | |
echo "" | |
echo -n "Flush Apple Type Server (ATS) cache? (Y/n): "; read AppleATS_CACHE | |
if [ -z $AppleATS_CACHE ] || [ "$AppleATS_CACHE" = "y" ] || [ "$AppleATS_CACHE" = "Y" ]; then | |
echo "Flushing Apple Type Services font cache ..." | |
sudo rm -rf `lsof | grep com.apple.ATS/annex.aux \ | |
| grep Finder | cut -c 66-139` | |
sudo rm -rf /private/var/folders/*/*/-Caches-/com.apple.ATS | |
fi | |
echo "" | |
echo -n "Rebuild Spotlight Index? (Y/n): "; read SPTLGHT | |
if [ -z $SPTLGHT ] || [ "$SPTLGHT" = "y" ] || [ "$SPTLGHT" = "Y" ]; then | |
echo "Rebuilding Spotlight Index ..." | |
sudo mdutil -i on; | |
fi | |
echo "" | |
# All done! We can go ahead and restart the computer now. | |
echo "Maintenance tasks have completed." | |
echo "If you have performed system level tasks, please restart now." | |
echo "Otherwise, please log out and back in." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment