mirror of
https://github.com/tw93/Mole.git
synced 2026-02-16 21:04:11 +00:00
Spotlight cache cleaning moved to the optimize command
This commit is contained in:
@@ -127,6 +127,7 @@ EOF
|
|||||||
items+=('recent_items|Recent Items|Clear recent apps/documents/servers lists|true')
|
items+=('recent_items|Recent Items|Clear recent apps/documents/servers lists|true')
|
||||||
items+=('log_cleanup|Diagnostics Cleanup|Purge old diagnostic & crash logs|true')
|
items+=('log_cleanup|Diagnostics Cleanup|Purge old diagnostic & crash logs|true')
|
||||||
items+=('startup_cache|Startup Cache Rebuild|Rebuild kext caches & prelinked kernel|true')
|
items+=('startup_cache|Startup Cache Rebuild|Rebuild kext caches & prelinked kernel|true')
|
||||||
|
items+=('spotlight_cache_cleanup|Spotlight Cache Cleanup|Clear CoreSpotlight user cache|false')
|
||||||
|
|
||||||
# Output items as JSON
|
# Output items as JSON
|
||||||
local first=true
|
local first=true
|
||||||
|
|||||||
@@ -216,8 +216,6 @@ clean_project_caches() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Clean Spotlight user caches
|
# Clean Spotlight user caches
|
||||||
# Cleans CoreSpotlight index cache and Spotlight saved state
|
|
||||||
# System Spotlight index (/System/Volumes/Data/.Spotlight-V100) is never touched
|
|
||||||
clean_spotlight_caches() {
|
clean_spotlight_caches() {
|
||||||
local cleaned_size=0
|
local cleaned_size=0
|
||||||
local cleaned_count=0
|
local cleaned_count=0
|
||||||
|
|||||||
@@ -80,8 +80,7 @@ clean_macos_system_caches() {
|
|||||||
safe_clean ~/Library/Saved\ Application\ State/* "Saved application states"
|
safe_clean ~/Library/Saved\ Application\ State/* "Saved application states"
|
||||||
safe_clean ~/Library/Caches/com.apple.spotlight "Spotlight cache"
|
safe_clean ~/Library/Caches/com.apple.spotlight "Spotlight cache"
|
||||||
|
|
||||||
# Clean Spotlight user caches (CoreSpotlight can grow very large)
|
# MOVED: Spotlight cache cleanup moved to optimize command
|
||||||
clean_spotlight_caches
|
|
||||||
|
|
||||||
safe_clean ~/Library/Caches/com.apple.photoanalysisd "Photo analysis cache"
|
safe_clean ~/Library/Caches/com.apple.photoanalysisd "Photo analysis cache"
|
||||||
safe_clean ~/Library/Caches/com.apple.akd "Apple ID cache"
|
safe_clean ~/Library/Caches/com.apple.akd "Apple ID cache"
|
||||||
|
|||||||
@@ -163,6 +163,7 @@ TouchID sudo check|check_touchid|config_check
|
|||||||
Rosetta 2 check|check_rosetta|config_check
|
Rosetta 2 check|check_rosetta|config_check
|
||||||
Git configuration check|check_git_config|config_check
|
Git configuration check|check_git_config|config_check
|
||||||
Login items check|check_login_items|config_check
|
Login items check|check_login_items|config_check
|
||||||
|
Spotlight cache cleanup|spotlight_cache|system_optimization
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -410,6 +410,56 @@ opt_fix_broken_configs() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Clean Spotlight user caches
|
||||||
|
opt_spotlight_cache_cleanup() {
|
||||||
|
# Check whitelist
|
||||||
|
if is_whitelisted "spotlight_cache"; then
|
||||||
|
echo -e "${GRAY}${ICON_SUCCESS}${NC} Spotlight cache cleanup (whitelisted)"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${BLUE}${ICON_ARROW}${NC} Cleaning Spotlight user caches..."
|
||||||
|
|
||||||
|
local cleaned_count=0
|
||||||
|
local total_size_kb=0
|
||||||
|
|
||||||
|
# CoreSpotlight user cache (can grow very large)
|
||||||
|
local spotlight_cache="$HOME/Library/Metadata/CoreSpotlight"
|
||||||
|
if [[ -d "$spotlight_cache" ]]; then
|
||||||
|
local size_kb=$(get_path_size_kb "$spotlight_cache")
|
||||||
|
if [[ "$size_kb" -gt 0 ]]; then
|
||||||
|
local size_human=$(bytes_to_human "$((size_kb * 1024))")
|
||||||
|
if safe_remove "$spotlight_cache" true; then
|
||||||
|
echo -e " ${GREEN}${ICON_SUCCESS}${NC} CoreSpotlight cache ${GREEN}($size_human)${NC}"
|
||||||
|
((cleaned_count++))
|
||||||
|
((total_size_kb += size_kb))
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Spotlight saved application state
|
||||||
|
local spotlight_state="$HOME/Library/Saved Application State/com.apple.spotlight.Spotlight.savedState"
|
||||||
|
if [[ -d "$spotlight_state" ]]; then
|
||||||
|
local size_kb=$(get_path_size_kb "$spotlight_state")
|
||||||
|
if [[ "$size_kb" -gt 0 ]]; then
|
||||||
|
local size_human=$(bytes_to_human "$((size_kb * 1024))")
|
||||||
|
if safe_remove "$spotlight_state" true; then
|
||||||
|
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Spotlight state ${GREEN}($size_human)${NC}"
|
||||||
|
((cleaned_count++))
|
||||||
|
((total_size_kb += size_kb))
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $cleaned_count -gt 0 ]]; then
|
||||||
|
local total_human=$(bytes_to_human "$((total_size_kb * 1024))")
|
||||||
|
echo -e "${GREEN}${ICON_SUCCESS}${NC} Cleaned $cleaned_count items ${GREEN}($total_human)${NC}"
|
||||||
|
echo -e "${YELLOW}${ICON_WARNING}${NC} System settings may require logout/restart to display correctly"
|
||||||
|
else
|
||||||
|
echo -e "${GREEN}${ICON_SUCCESS}${NC} No Spotlight caches to clean"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Execute optimization by action name
|
# Execute optimization by action name
|
||||||
execute_optimization() {
|
execute_optimization() {
|
||||||
local action="$1"
|
local action="$1"
|
||||||
@@ -430,6 +480,7 @@ execute_optimization() {
|
|||||||
local_snapshots) opt_local_snapshots ;;
|
local_snapshots) opt_local_snapshots ;;
|
||||||
developer_cleanup) opt_developer_cleanup ;;
|
developer_cleanup) opt_developer_cleanup ;;
|
||||||
fix_broken_configs) opt_fix_broken_configs ;;
|
fix_broken_configs) opt_fix_broken_configs ;;
|
||||||
|
spotlight_cache_cleanup) opt_spotlight_cache_cleanup ;;
|
||||||
*)
|
*)
|
||||||
echo -e "${RED}${ICON_ERROR}${NC} Unknown action: $action"
|
echo -e "${RED}${ICON_ERROR}${NC} Unknown action: $action"
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
Reference in New Issue
Block a user