Skip to content

Instantly share code, notes, and snippets.

@DasLampe
Created October 22, 2012 21:15
Show Gist options
  • Save DasLampe/3934414 to your computer and use it in GitHub Desktop.
Save DasLampe/3934414 to your computer and use it in GitHub Desktop.
[Mac OS X] Fix broken permissions and stop spotlight reindexing
#! /bin/bash
########################################################
#Copright: 2012, DasLampe <daslampe@lano-crew.org>
#Original Source: https://gist.github.com/gists/3934414/
#
#Licence Information:
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or any later version.
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#See <http://www.gnu.org/licenses/> for more informations.
########################################################
echo "[INFO] (c) 2012 DasLampe <daslampe@lano-crew.org>"
echo "[INFO] Run this script with sudo permissions, else it fails. 'sudo sh $0'"
echo "[STATUS] Try to locate the problem"
if [[ `cat /var/log/system.log | grep '(Warning) Server: No stores registered for metascope "kMDQueryScopeComputer"'` ]]; then
echo "[STATUS] Find error! Try to fix it."
echo "[INFO] While the script fix the problem, it's possible your system is slower than before. Don't worry about this! After the procedure your system is faster than before. ;)"
echo "[INFO] IMPORTANT: Please don't close your Mac in the next step, else you can destroy your system!!!"
echo "[STATUS] Start: Repair Permissions on Disk."
diskutil repairPermissions /
echo "[STATUS] Finish: Repair Permissions"
echo "[STATUS] Start: Delete old Spotlight files"
rm -r /.Spotlight*
echo "[STATUS] Finish: Delte old Spotlight files"
echo "[STATUS] Start: Rebuild Spotlight index"
mdutil -i off /
mdutil -E /
mdutil -i on /
echo "[INFO] You can close your Mac. Now Spotlight start reindexing your files and can paused this."
echo "[INFO] The scripts ends here. Mac OS X finished the procedure in the next time."
echo "[INFO] After a few hours you system is faster than before."
else
echo "[INFO] Can't find any errors. Try to find the problem by your self."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment