mirror of
https://github.com/tw93/Mole.git
synced 2026-02-10 02:04:17 +00:00
feat: add new system optimization tasks and implement orphaned startup item cleanup
This commit is contained in:
@@ -33,7 +33,7 @@ fix_broken_preferences() {
|
||||
plutil -lint "$plist_file" > /dev/null 2>&1 && continue
|
||||
|
||||
# Remove broken plist
|
||||
rm -f "$plist_file" 2> /dev/null || true
|
||||
safe_remove "$plist_file" true > /dev/null 2>&1 || true
|
||||
((broken_count++))
|
||||
done < <(command find "$prefs_dir" -maxdepth 1 -name "*.plist" -type f 2> /dev/null || true)
|
||||
|
||||
@@ -53,7 +53,7 @@ fix_broken_preferences() {
|
||||
|
||||
plutil -lint "$plist_file" > /dev/null 2>&1 && continue
|
||||
|
||||
rm -f "$plist_file" 2> /dev/null || true
|
||||
safe_remove "$plist_file" true > /dev/null 2>&1 || true
|
||||
((broken_count++))
|
||||
done < <(command find "$byhost_dir" -name "*.plist" -type f 2> /dev/null || true)
|
||||
fi
|
||||
@@ -61,54 +61,4 @@ fix_broken_preferences() {
|
||||
echo "$broken_count"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Broken Login Items Cleanup
|
||||
# Find and remove login items pointing to non-existent files
|
||||
# ============================================================================
|
||||
|
||||
# Clean login items with missing executables
|
||||
fix_broken_login_items() {
|
||||
local launch_agents_dir="$HOME/Library/LaunchAgents"
|
||||
[[ -d "$launch_agents_dir" ]] || return 0
|
||||
|
||||
# Check whitelist
|
||||
if command -v is_whitelisted > /dev/null && is_whitelisted "check_login_items"; then return 0; fi
|
||||
|
||||
local broken_count=0
|
||||
|
||||
while IFS= read -r plist_file; do
|
||||
[[ -f "$plist_file" ]] || continue
|
||||
|
||||
# Skip system items
|
||||
local filename
|
||||
filename=$(basename "$plist_file")
|
||||
case "$filename" in
|
||||
com.apple.*)
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
|
||||
# Extract Program or ProgramArguments[0] from plist using plutil
|
||||
local program=""
|
||||
program=$(plutil -extract Program raw "$plist_file" 2> /dev/null || echo "")
|
||||
|
||||
if [[ -z "$program" ]]; then
|
||||
# Try ProgramArguments array (first element)
|
||||
program=$(plutil -extract ProgramArguments.0 raw "$plist_file" 2> /dev/null || echo "")
|
||||
fi
|
||||
|
||||
# Expand tilde in path if present
|
||||
program="${program/#\~/$HOME}"
|
||||
|
||||
# Skip if no program found or program exists
|
||||
[[ -z "$program" ]] && continue
|
||||
[[ -e "$program" ]] && continue
|
||||
|
||||
# Program doesn't exist - this is a broken login item
|
||||
launchctl unload "$plist_file" 2> /dev/null || true
|
||||
rm -f "$plist_file" 2> /dev/null || true
|
||||
((broken_count++))
|
||||
done < <(command find "$launch_agents_dir" -name "*.plist" -type f 2> /dev/null || true)
|
||||
|
||||
echo "$broken_count"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user