#!/bin/bash # 特定的关键词列表(保留这些应用不卸载) # 只要包名或应用名称中包含以下列表中的关键词,就会被保留 KEEP_KEYWORDS=( "WebDriverAgentRunner" "FastbotRunner" "com.apple." # 在这里添加你想保留的应用的关键词 ) echo "正在获取设备上的应用列表..." # 运行 ios apps --list 并由于有类似 {"level":"info"... 这样的日志结构,我们过滤掉开头为 { 的日志行 app_lines=$(ios apps --list | grep -v '^{') while IFS= read -r line; do # 忽略空行 if [[ -z "$line" ]]; then continue fi # 提取第一列,第一列是 bundle_id bundle_id=$(echo "$line" | awk '{print $1}') if [[ -z "$bundle_id" ]]; then continue fi # 检查是否包含保留关键词 should_keep=0 for keyword in "${KEEP_KEYWORDS[@]}"; do if echo "$line" | grep -iq "$keyword"; then should_keep=1 break fi done if [[ $should_keep -eq 0 ]]; then echo "[-] 正在卸载: $line" ios uninstall "$bundle_id" else echo "[+] 保留应用: $line" fi done <<< "$app_lines" echo "清理完成!"