我四处寻找,但没找到。在开始编码之前,我想问一下……
我定期通过终端使用brew
、macports
、pip
、yarn
等更新我的 Mac。因此,我开始通过重新安装我的应用程序,brew cask
以便定期更新它们。这非常机械化,我相信有办法实现自动化。它所需要做的就是将文件夹ls
中的应用程序与 和 尚未存在的应用程序Applications
进行比较。如果结果不一致,更全面的脚本将使用并要求用户选择并确认。brew cask list
brew cask --force install
brew search
答案1
已分类!
cd /Applications
brew cask list -1 > apps.txt
brew search --casks > casks.txt
for f in *.app do
if grep -Fixq ${${f%.*}// /-} casks.txt && ! grep -Fixq ${${f%.*}// /-} apps.txt
then HOMEBREW_NO_AUTO_UPDATE=1 brew cask install --force ${${f%.*}// /-}
fi
done
答案2
我昨晚写了这个,希望它有帮助,应该很快就会在 github 上发布。
该脚本旨在帮助管理系统上安装的 macOS 应用程序,尤其是那些可通过 Homebrew Cask 获得的应用程序。该脚本的主要目的是识别系统上安装但不受 Homebrew Cask 管理的应用程序,并为用户提供使用 Homebrew Cask 安装这些应用程序的选项。
#!/usr/bin/env bash
# Change the current directory to /Applications, where most macOS applications are installed
cd /Applications
# Generate two text files: apps.txt and casks.txt
# apps.txt contains a list of applications already installed using Homebrew Cask
# casks.txt contains a list of all available Homebrew Cask applications
brew list --cask > apps.txt
brew search --casks "" > casks.txt
# Iterate through all .app files in the /Applications directory
for f in *.app; do
# Check if the application name is present in the casks.txt file (available through Homebrew Cask)
# and not present in the apps.txt file (not currently installed using Homebrew Cask)
if grep -Fixq "${${f%.*}// /-}" casks.txt && ! grep -Fixq "${${f%.*}// /-}" apps.txt; then
# Assign the original file name to a variable
original_file_name="$f"
# Assign the Homebrew Cask-friendly application name to a variable
brew_app_name="${${f%.*}// /-}"
# Prompt the user to confirm the installation
while true; do
read -p "Do you want to install '$brew_app_name'? (y/n/b) " confirmation
case "$confirmation" in
[yY])
echo "Installing '$brew_app_name'..."
brew cask install --force "$brew_app_name"
break
;;
[nN])
echo "Skipping installation of '$brew_app_name'."
break
;;
[bB])
echo "Backing up '$original_file_name' to /Users/macuser/appbackups..."
if [ ! -d "/Users/macuser/appbackups" ]; then
echo "Creating /Users/macuser/appbackups directory..."
mkdir -p "/Users/macuser/appbackups"
fi
mv "$original_file_name" "/Users/macuser/appbackups/$original_file_name"
echo "Installing '$brew_app_name'..."
HOMEBREW_NO_AUTO_UPDATE=1 brew cask install --force "$brew_app_name"
break
;;
*)
echo "Invalid response. Please try again."
continue
;;
esac
done
fi
done
# Remove the temporary files
rm apps.txt casks.txt