Mac版QQ和微信聊天记录 软链接到外置硬盘 & Infuse缓存

创建时间
Sep 16, 2025 01:54 PM
编辑日期
Last updated September 17, 2025
属性
标签
先将对应文件复制到目标位置,然后删除Library中的nt_qq_*2.0b4.0.9 ,后续链接会在目录下生成一个带有小箭头的文件
notion image
QQ 聊天记录位置,主要信息都存在这个文件里。获得路径的一个简单方法就是右键聊天框的图片,在finder中打开,再用Option键显示路径
"/Users/用户名/Library/Application Support/QQ/nt_qq_开头的最长的那个文件"
创建软链接
ln -s /Volumes/外置硬盘/qq_cache/nt_qq_开头的最长的那个文件 "/Users/用户名/Library/Application Support/QQ/nt_qq_开头的最长的那个文件"

微信 聊天记录位置
"/Users/用户名/Library/Containers/com.tencent.xinWeChat/Data/Library/Application Support/com.tencent.xinWeChat/2.0b4.0.9"
创建软链接
ln -s /Volumes/外置硬盘/wechat_cache/2.0b4.0.9 "/Users/用户名/Library/Containers/com.tencent.xinWeChat/Data/Library/Application Support/com.tencent.xinWeChat/2.0b4.0.9"
两个都需要重制签名
sudo codesign --sign - --force --deep /Applications/WeChat.app sudo codesign --sign - --force --deep /Applications/QQ.app

Infuse的在线视频缓存位置是~/Library/Containers/com.firecore.infuse/Data/tmp/FileCache 但无法通过链接方式用外置硬盘存储。有Infuse的程序维持Data 文件不受影响。
对于Infuse的下载位置,参考
创建一个script.sh脚本用于执行,软链接方法无效,以下代码我增加了解绑功能,并将HFS+J 文件系统修改为APFS
但是,这种方法无法在Infuse中删除下载的视频。
#!/bin/bash # ============================================================================== # Infuse Sparse Image Management Script # # Version: 2.1 # Changelog: # - v2.1: Fixed filename mismatch between .sparseimage and .sparsebundle. # Hardened creation logic to exit on failure. # Improved find command to correctly locate bundles. # ============================================================================== # --- Configuration --- SPARSE_IMAGE_NAME="Infuse.sparsebundle" CURRENT_USER=$(whoami) MOUNT_POINT="/Users/$CURRENT_USER/Movies/Infuse" BACKUP_FOLDER="/Users/$CURRENT_USER/Movies/Infuse_" PLIST_PATH="$HOME/Library/LaunchAgents/com.user.infuse.mount.plist" SCRIPT_PATH="$(cd "$(dirname "$0")" && pwd)/$(basename "$0")" # --- Function Definitions --- execute_or_debug() { eval "$@" } # -------------------------- # UNINSTALLATION LOGIC # -------------------------- uninstall_service() { echo "----------------------------------------------------" echo " Starting Uninstallation Process" echo "----------------------------------------------------" # Step 1: Stop and remove the LaunchAgent echo "--> Step 1 of 4: Removing auto-run service..." if [ -f "$PLIST_PATH" ]; then execute_or_debug "launchctl unload '$PLIST_PATH' 2>/dev/null" execute_or_debug "rm '$PLIST_PATH'" echo " Service unloaded and configuration file removed." else echo " Auto-run service not found. Skipping." fi echo # Step 2: Unmount the disk image if it's currently mounted echo "--> Step 2 of 4: Unmounting the sparse image..." if mount | grep -q "on $MOUNT_POINT"; then execute_or_debug "hdiutil detach '$MOUNT_POINT'" echo " Successfully unmounted from '$MOUNT_POINT'." else echo " The sparse image is not currently mounted at the target location. Skipping." fi echo # Step 3: Find the sparse image and migrate data back echo "--> Step 3 of 4: Migrating data back to local folder..." SPARSE_IMAGE_PATH=$(find /Volumes -name "$SPARSE_IMAGE_NAME" \( -type f -o -type d \) -maxdepth 4 2>/dev/null | head -n 1) if [ -z "$SPARSE_IMAGE_PATH" ]; then echo " WARNING: Could not find '$SPARSE_IMAGE_NAME'." echo " You will need to manually find it, mount it, and copy your data to:" echo " '$MOUNT_POINT'" else echo " Found sparse image at: '$SPARSE_IMAGE_PATH'" read -p " Do you want to move all data from this image back to your local folder? [y/N]: " answer if [[ "$answer" =~ ^[Yy]$ ]]; then echo " Temporarily mounting the sparse image to migrate data..." TEMP_MOUNT_INFO=$(hdiutil attach "$SPARSE_IMAGE_PATH") TEMP_MOUNT_POINT=$(echo "$TEMP_MOUNT_INFO" | grep '/Volumes/' | awk '{$1=$2=""; print $0}' | sed 's/^[ \t]*//') if [ -z "$TEMP_MOUNT_POINT" ]; then echo " ERROR: Failed to mount the sparse image. Please perform data migration manually." else echo " Mounted at '$TEMP_MOUNT_POINT'." echo " Moving files... This may take a while." execute_or_debug "rsync -av --remove-source-files '$TEMP_MOUNT_POINT/' '$MOUNT_POINT/'" echo " Data migration complete." execute_or_debug "hdiutil detach '$TEMP_MOUNT_POINT'" echo " Temporary volume unmounted." read -p " Data has been moved. Do you want to DELETE the sparse image file now? [y/N]: " del_answer if [[ "$del_answer" =~ ^[Yy]$ ]]; then execute_or_debug "rm -rf '$SPARSE_IMAGE_PATH'" echo " '$SPARSE_IMAGE_NAME' has been deleted." else echo " The sparse image file has been kept at '$SPARSE_IMAGE_PATH'." fi fi else echo " Data migration skipped. Your data remains in '$SPARSE_IMAGE_PATH'." fi fi echo # Step 4: Clean up backup folder echo "--> Step 4 of 4: Cleaning up..." if [ -d "$BACKUP_FOLDER" ]; then execute_or_debug "rm -rf '$BACKUP_FOLDER'" echo " Removed backup folder '$BACKUP_FOLDER'." fi echo; echo "----------------------------------------------------"; echo " Uninstallation Complete!"; echo "----------------------------------------------------" echo "Infuse will now use the standard local directory." } # -------------------------- # SETUP AND RUN LOGIC # -------------------------- run_setup() { echo "----------------------------------------------------" echo " Starting Setup / Run Process" echo "----------------------------------------------------" # Search for the sparse image file echo "Searching for '$SPARSE_IMAGE_NAME' on all volumes..." SPARSE_IMAGE_PATH=$(find /Volumes -name "$SPARSE_IMAGE_NAME" \( -type f -o -type d \) -maxdepth 4 2>/dev/null | head -n 1) # Create if not found if [ -z "$SPARSE_IMAGE_PATH" ]; then echo "Sparse image not found. Let's create one." OS_DRIVE=$(df / | tail -1 | awk '{print $1}' | xargs -I {} basename {}) select vol in $(ls /Volumes | grep -v "$OS_DRIVE"); do SPARSE_IMAGE_PATH="/Volumes/$vol/$SPARSE_IMAGE_NAME" read -p "Enter the size for the new sparse image (e.g., 500g): " size size=${size:-500g} # Default size echo "Creating a ${size} APFS sparse bundle at '$SPARSE_IMAGE_PATH'..." execute_or_debug "hdiutil create -size $size -type SPARSEBUNDLE -fs APFS -volname Infuse \"$SPARSE_IMAGE_PATH\"" if [ $? -ne 0 ]; then echo "ERROR: hdiutil create command failed. Exiting." exit 1 fi break done fi echo "Using sparse image at: $SPARSE_IMAGE_PATH" # Check if already mounted correctly if mount | grep -q "on $MOUNT_POINT"; then echo "Sparse image is already mounted correctly. Nothing to do." exit 0 fi # Detach if mounted elsewhere if hdiutil info | grep -q "$SPARSE_IMAGE_PATH"; then echo "Image is mounted elsewhere. Detaching it first..." execute_or_debug "hdiutil detach \"$(hdiutil info | grep \"$SPARSE_IMAGE_PATH\" | awk '{print $1}')\"" fi # Prepare mount point and backup existing files execute_or_debug "mkdir -p \"$MOUNT_POINT\"" if [ "$(find \"$MOUNT_POINT\" -mindepth 1 -not -name '.*' 2>/dev/null | wc -l)" -gt 0 ]; then echo "Backing up existing files from '$MOUNT_POINT'..." execute_or_debug "mkdir -p \"$BACKUP_FOLDER\"" execute_or_debug "mv \"$MOUNT_POINT\"/* \"$BACKUP_FOLDER\"/" fi # Compact and attach the sparse image echo "Compacting the sparse image (this may take a moment)..." execute_or_debug "hdiutil compact \"$SPARSE_IMAGE_PATH\" -batteryallowed" echo "Attaching sparse image to '$MOUNT_POINT'..." execute_or_debug "hdiutil attach -owners on \"$SPARSE_IMAGE_PATH\" -mountpoint \"$MOUNT_POINT\" -nobrowse" # Move files from backup folder to the new mount point if [ -d "$BACKUP_FOLDER" ] && [ "$(ls -A $BACKUP_FOLDER)" ]; then echo "Moving files from backup folder to the mount point..." execute_or_debug "mv \"$BACKUP_FOLDER\"/* \"$MOUNT_POINT\"/" execute_or_debug "rm -r \"$BACKUP_FOLDER\"" fi echo; echo "----------------------------------------------------"; echo " Setup Complete! Infuse is ready."; echo "----------------------------------------------------" # Install service if not already installed if [ ! -f "$PLIST_PATH" ]; then read -p "Do you want to install this script to run automatically on login? [Y/n]: " answer if [[ ! "$answer" =~ ^[Nn]$ ]]; then echo "Installing auto-run service..." execute_or_debug "chmod +x \"$SCRIPT_PATH\"" cat <<EOL > "$PLIST_PATH" <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.user.infuse.mount</string> <key>ProgramArguments</key> <array> <string>$SCRIPT_PATH</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist> EOL execute_or_debug "launchctl load \"$PLIST_PATH\"" echo "Service installed successfully." fi fi } # --- Main Script Logic --- clear echo "======================================================" echo " Infuse Sparse Image Management Script (v2.1)" echo "======================================================" echo echo "What would you like to do?" echo " 1) Setup / Run Infuse with sparse image (Default)" echo " 2) Uninstall and revert to local storage" echo " q) Quit" echo read -p "Enter your choice [1]: " choice choice=${choice:-1} echo case $choice in 1) run_setup ;; 2) uninstall_service ;; q) echo "Exiting."; exit 0 ;; *) echo "Invalid option. Exiting."; exit 1 ;; esac exit 0
  • Would you like to create a sparse image? y 必须新创建
  • Select the external storage to use. 选择外置硬盘,会创建在根目录
  • Enter the size of the sparse image (e.g., 100g for 100GB). 自己选择
  • Do you want an expanding volume? (y/n) 自己选择
  • Would you like to install the script as a service? y 自启动
 
另一个版本,卸载功能有点问题
#!/bin/bash # ============================================================================== # Infuse Sparse Image Management Script # # Version: 3.0 (Interactive Setup & Config File) # Changelog: # - v3.0: Removed hard-coded TARGET_DIRECTORY. Script now interactively prompts # for the path on first run and saves it to a config file. Added menu # option to change the saved path. # - v2.3: Hardened script by quoting all path variables for space handling. # ============================================================================== # --- Configuration --- SPARSE_IMAGE_NAME="Infuse.sparsebundle" CURRENT_USER=$(whoami) CONFIG_FILE="$HOME/.infuse_script.conf" MOUNT_POINT="/Users/$CURRENT_USER/Movies/Infuse" BACKUP_FOLDER="/Users/$CURRENT_USER/Movies/Infuse_Backup" PLIST_PATH="$HOME/Library/LaunchAgents/com.user.infuse.mount.plist" SCRIPT_PATH="$(cd "$(dirname "$0")" && pwd)/$(basename "$0")" # --- Function Definitions --- execute_or_debug() { eval "$@" } # -------------------------- # PATH CONFIGURATION LOGIC # -------------------------- get_target_directory() { if [ -f "$CONFIG_FILE" ] && [ -s "$CONFIG_FILE" ]; then cat "$CONFIG_FILE" else return 1 fi } prompt_and_save_path() { echo "首次运行或配置丢失,请设置您的虚拟磁盘存放目录。" echo "这应该是一个位于您外置硬盘上的文件夹的【完整路径】。" echo "例如: /Volumes/MyExternalSSD/InfuseData" # 使用 read -e 允许用户使用 Tab 键自动补全路径 read -e -p "请输入路径: " user_path # 去除路径末尾可能存在的斜杠 user_path="${user_path%/}" if [ -z "$user_path" ]; then echo "错误:路径不能为空。脚本退出。" exit 1 fi # 检查路径是否以 /Volumes/ 开头,提醒用户使用外置硬盘 if [[ ! "$user_path" =~ ^/Volumes/ ]]; then read -p "警告:您选择的路径似乎不在外置硬盘上。确定要继续吗? [y/N]: " confirm if [[ ! "$confirm" =~ ^[Yy]$ ]]; then echo "操作已取消。脚本退出。" exit 1 fi fi echo "$user_path" > "$CONFIG_FILE" echo "路径已成功保存到: $CONFIG_FILE" echo } change_path() { echo "--- 更改已保存的路径 ---" if [ -f "$CONFIG_FILE" ]; then echo "当前已保存的路径是: '$(cat "$CONFIG_FILE")'" fi prompt_and_save_path echo "路径已更新!" } # -------------------------- # UNINSTALLATION LOGIC # -------------------------- uninstall_service() { echo "----------------------------------------------------" echo " 开始卸载..." # ... [uninstallation logic remains the same as v2.3] ... echo "--> 步骤 5/5: 清理配置文件..." if [ -f "$CONFIG_FILE" ]; then execute_or_debug "rm '$CONFIG_FILE'" echo " 已移除配置文件 '$CONFIG_FILE'。" fi echo " 卸载完成!" echo "----------------------------------------------------" } # -------------------------- # SETUP AND RUN LOGIC # -------------------------- run_setup() { # ### NEW INTERACTIVE LOGIC ### TARGET_DIRECTORY=$(get_target_directory) if [ $? -ne 0 ]; then prompt_and_save_path TARGET_DIRECTORY=$(get_target_directory) fi echo "----------------------------------------------------" echo " 开始设置 / 运行" echo " 将使用已保存的目录: '$TARGET_DIRECTORY'" echo "----------------------------------------------------" execute_or_debug "mkdir -p \"$TARGET_DIRECTORY\"" SPARSE_IMAGE_PATH="$TARGET_DIRECTORY/$SPARSE_IMAGE_NAME" if [ ! -e "$SPARSE_IMAGE_PATH" ]; then echo "未找到虚拟磁盘,现在开始创建。" read -p "请输入新建虚拟磁盘的大小 (例如: 500g, 1t): " size size=${size:-500g} echo "正在路径 '$SPARSE_IMAGE_PATH' 创建一个大小为 ${size} 的APFS虚拟磁盘..." execute_or_debug "hdiutil create -size $size -type SPARSEBUNDLE -fs APFS -volname Infuse \"$SPARSE_IMAGE_PATH\"" if [ $? -ne 0 ]; then echo "错误: hdiutil create 命令执行失败,脚本退出。" exit 1 fi fi # ... [The rest of the run_setup logic is the same as v2.3] ... echo "将使用虚拟磁盘: $SPARSE_IMAGE_PATH" if mount | grep -q "on \"$MOUNT_POINT\""; then echo "虚拟磁盘已正确挂载,无需操作。" exit 0 fi if hdiutil info | grep -q "$SPARSE_IMAGE_PATH"; then echo "磁盘被挂载在其他位置,正在先行卸载..." execute_or_debug "hdiutil detach \"$(hdiutil info | grep \"$SPARSE_IMAGE_PATH\" | awk '{print $1}')\"" fi execute_or_debug "mkdir -p \"$MOUNT_POINT\"" if [ "$(find \"$MOUNT_POINT\" -mindepth 1 -not -name '.*' 2>/dev/null | wc -l)" -gt 0 ]; then echo "正在备份 '$MOUNT_POINT' 中的现有文件..." execute_or_debug "mkdir -p \"$BACKUP_FOLDER\"" execute_or_debug "mv \"$MOUNT_POINT\"/* \"$BACKUP_FOLDER\"/" fi echo "正在优化虚拟磁盘 (可能需要一点时间)..." execute_or_debug "hdiutil compact \"$SPARSE_IMAGE_PATH\" -batteryallowed" echo "正在将虚拟磁盘挂载到 '$MOUNT_POINT'..." execute_or_debug "hdiutil attach -owners on \"$SPARSE_IMAGE_PATH\" -mountpoint \"$MOUNT_POINT\" -nobrowse" if [ -d "$BACKUP_FOLDER" ] && [ "$(ls -A \"$BACKUP_FOLDER\")" ]; then echo "正在将备份文件移回挂载点..." execute_or_debug "mv \"$BACKUP_FOLDER\"/* \"$MOUNT_POINT\"/" execute_or_debug "rm -r \"$BACKUP_FOLDER\"" fi echo; echo "----------------------------------------------------"; echo " 设置完成! Infuse 已准备就绪。"; echo "----------------------------------------------------" if [ ! -f "$PLIST_PATH" ]; then read -p "是否要安装开机自动运行服务? [Y/n]: " answer if [[ ! "$answer" =~ ^[Nn]$ ]]; then echo "正在安装自动运行服务..." execute_or_debug "chmod +x \"$SCRIPT_PATH\"" cat <<EOL > "$PLIST_PATH" <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.user.infuse.mount</string> <key>ProgramArguments</key> <array> <string>$SCRIPT_PATH</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist> EOL execute_or_debug "launchctl load \"$PLIST_PATH\"" echo "服务安装成功。" fi fi } # --- Main Script Logic --- clear echo "======================================================" echo " Infuse 虚拟磁盘管理脚本 (v3.0)" echo "======================================================" echo echo "请选择操作:" echo " 1) 设置 / 运行 (默认)" echo " 2) 更改已保存的路径" echo " 3) 卸载并恢复到本地存储" echo " q) 退出" echo read -p "输入您的选择 [1]: " choice choice=${choice:-1} echo case $choice in 1) run_setup ;; 2) change_path ;; 3) uninstall_service ;; # Adjusted number q) echo "退出。"; exit 0 ;; *) echo "无效选项,退出。"; exit 1 ;; esac exit 0