最近重装了我的 Mac mini,用这篇文章记录一下在重装一台电脑之后我做的事情,以便后续我更快配置我的 Mac。

📑 目录

⚙️ 系统基础配置

🧩 1. 系统偏好设置

# 启用全键盘控制
defaults write -g AppleKeyboardUIMode -int 3

# 开启按住重复输入
defaults write -g ApplePressAndHoldEnabled -bool false
defaults write -g InitialKeyRepeat -int 15
defaults write -g KeyRepeat -int 1

# 关闭智能替换功能
defaults write -g NSAutomaticDashSubstitutionEnabled -bool false
defaults write -g NSAutomaticPeriodSubstitutionEnabled -bool false
defaults write -g NSAutomaticQuoteSubstitutionEnabled -bool false

# 禁用自动大写
defaults write -g NSAutomaticCapitalizationEnabled -bool false

# 禁用自动拼写纠正
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false

# 使用展开的保存面板
defaults write -g NSNavPanelExpandedStateForSaveMode -bool true
defaults write -g NSNavPanelExpandedStateForSaveMode2 -bool true

# 提高窗口缩放速度
defaults write -g NSWindowResizeTime -float 0.001

# 默认保存到本地而非 iCloud
defaults write -g NSDocumentSaveNewDocumentsToCloud -bool true

# 滚动条点击跳转到点击位置
defaults write -g AppleScrollerPagingBehavior -bool true

# 偏好使用标签页打开文档
defaults write -g AppleWindowTabbingMode -string always

🧭 2. Dock 设置

# 设置图标大小与位置
defaults write com.apple.dock orientation -string left

# 启用自动隐藏并透明显示隐藏的应用图标
defaults write com.apple.dock autohide -bool true
defaults write com.apple.dock showhidden -bool true

# 不显示最近使用的应用
defaults write com.apple.dock show-recents -bool false

# 清除固定应用
defaults write com.apple.dock persistent-apps -array ""

🗂️ 3. Finder 设置

# 允许 ⌘Q 退出 Finder
defaults write com.apple.finder QuitMenuItem -bool true

# 关闭修改扩展名时的警告
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false

# 显示所有文件与扩展名
defaults write com.apple.finder AppleShowAllExtensions -bool true
defaults write com.apple.finder AppleShowAllFiles -bool true

# 显示路径栏,使用列表视图
defaults write com.apple.finder ShowPathbar -bool true
defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv"

# 在标题栏显示完整路径
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true

# 默认在当前文件夹中搜索
defaults write com.apple.finder FXDefaultSearchScope -string SCcf

# 桌面保持干净
defaults write com.apple.finder ShowHardDrivesOnDesktop -bool false
defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool false
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool false
defaults write com.apple.finder ShowMountedServersOnDesktop -bool false

# 文件夹优先显示
defaults write com.apple.finder _FXSortFoldersFirst -bool true

# 新建窗口默认打开 HOME 目录
defaults write com.apple.finder NewWindowTarget -string PfHm
defaults write com.apple.finder NewWindowTargetPath -string "file://$HOME/"

# Quick Look 支持文字选择
defaults write com.apple.finder QLEnableTextSelection -bool true

# 信息面板中显示元数据但不预览内容
defaults write com.apple.finder FXInfoPanesExpanded -dict MetaData -bool true Preview -bool false

👆 4. Trackpad 设置

# 启用轻点点击
defaults write com.apple.AppleMultitouchTrackpad Clicking -bool true
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true

# 启用三指拖移
defaults write com.apple.AppleMultitouchTrackpad TrackpadThreeFingerDrag -bool true
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadThreeFingerDrag -bool true

📊 5. 活动监视器

# 默认按 CPU 排序
defaults write com.apple.ActivityMonitor SortColumn -string CPUUsage
defaults write com.apple.ActivityMonitor SortDirection -int 0

🚫 6. Launch Services

# 禁用下载应用的隔离机制
defaults write com.apple.LaunchServices LSQuarantine -bool false

🌐 7. Safari 设置

# 提升隐私保护
defaults write com.apple.Safari UniversalSearchEnabled -bool false
defaults write com.apple.Safari SuppressSearchSuggestions -bool true
defaults write com.apple.Safari SendDoNotTrackHTTPHeader -bool true

# 禁止自动打开下载内容
defaults write com.apple.Safari AutoOpenSafeDownloads -bool false

# 开发者菜单与调试功能
defaults write com.apple.Safari IncludeDevelopMenu -bool true
defaults write com.apple.Safari IncludeInternalDebugMenu -bool true
defaults write com.apple.Safari WebKitDeveloperExtras -bool true
defaults write com.apple.Safari WebKitDeveloperExtrasEnabledPreferenceKey -bool true
defaults write com.apple.Safari "com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled" -bool true

🧑‍🦯 8. 无障碍设置

# 设置光标大小
defaults write com.apple.universalaccess mouseDriverCursorSize -float 1.5

📸 9. 截图设置

# 修改截图默认文件名,不显示时间
defaults write com.apple.screencapture name -string screenshot
defaults write com.apple.screencapture include-date -bool false

💻 10. Desktop Services

# 不在 U 盘和网络磁盘中创建 .DS_Store 文件
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true

💽 11. 磁盘镜像设置

# 关闭磁盘镜像验证
defaults write com.apple.frameworks.diskimages skip-verify -bool true
defaults write com.apple.frameworks.diskimages skip-verify-locked -bool true
defaults write com.apple.frameworks.diskimages skip-verify-remote -bool true

💥 12. Crash Reporter

# 禁用崩溃报告弹窗
defaults write com.apple.CrashReporter DialogType -string none

📉 13. AdLib 广告追踪

# 关闭 Apple 广告追踪
defaults write com.apple.AdLib forceLimitAdTracking -bool true
defaults write com.apple.AdLib allowApplePersonalizedAdvertising -bool false
defaults write com.apple.AdLib allowIdentifierForAdvertising -bool false

🔓 14. 安装非 App Store 应用

# 允许安装任何来源的应用
sudo spctl --master-disable

执行完后建议注销重新登录以生效

🔋 15. 电源管理设置

# 基本睡眠设置
sudo pmset -a displaysleep 10  # 显示器睡眠时间:10分钟
sudo pmset -a sleep 15         # 系统睡眠时间:15分钟
sudo pmset -a disksleep 30     # 硬盘睡眠时间:30分钟

# 网络与设备唤醒设置
sudo pmset -a womp 0           # 禁止通过网络唤醒
sudo pmset -a acwake 0         # 电源变化时不唤醒
sudo pmset -a proximitywake 0  # 关闭 iCloud 设备唤醒
sudo pmset -a powernap 0       # 睡眠时不执行更新和备份

# 显示与性能设置
sudo pmset -a halfdim 1        # 睡眠前启用亮度渐暗效果
sudo pmset -b gpuswitch 2      # 电池模式:省电优先
sudo pmset -c gpuswitch 1      # 插电模式:性能优先

# 休眠模式设置
sudo pmset -a standby 1                # 启用 Hibernate 模式
sudo pmset -a standbydelayhigh 7200    # 高电量:2 小时后休眠
sudo pmset -a standbydelaylow 3600     # 低电量:1 小时后休眠
sudo pmset -a hibernatemode 3          # 将内存写入磁盘,关闭电源保持状态

🛠️ 开发环境搭建

🧰 1. 安装 Xcode Command Line Tools

# 安装 Xcode Command Line Tools
xcode-select --install

# 如果安装失败,可以尝试重新安装
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

🍺 2. 安装 Homebrew

# 安装 Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# 安装 mas 命令行工具,用于管理 App Store 应用
brew install mas

配置自动更新

# 配置 crontab 定时更新 (每周六 13:00 自动执行)
crontab -e

# 添加以下内容到 crontab
0 13 * * 6 /bin/bash -c "brew update && brew upgrade --greedy-auto-updates && brew cleanup --prune=all && mas upgrade"

⌨️ 3. 安装 Squirrel 输入法

# 安装 Squirrel 输入法
brew install --cask squirrel

# 克隆输入法配置
rm -rf ~/Library/Rime
git clone [email protected]:huyixi/rime-config.git ~/Library/Rime

🗑️ Mac 删除系统自带输入法

  1. 关闭 Mac 系统的 SIP (System Integrity Protection)

    • 关机
    • Intel 芯片的 Mac: 按住 Command + R 进入恢复模式
    • Apple 芯片的 Mac: 按住电源键 进入恢复模式
    • 进入恢复模式后,打开顶部菜单栏 实用工具 -> 终端
    • 输入以下命令关闭 SIP 模式:
      csrutil disable
      
    • 确认输出成功信息后重启系统
  2. 修改输入法配置

    • 打开终端,输入以下命令:
      sudo open ~/Library/Preferences/com.apple.HIToolbox.plist
      
    • 在该文件中,依次点开 Root -> AppleEnabledInputSources
    • 找到 KeyboardLayout NameABC 的那一列,将整列 item 删掉
    • 保存文件并重启系统
  3. 重新启用 SIP

    • 再次进入恢复模式,打开终端
    • 输入命令:
      csrutil enable
      
    • 重启系统

🔑 4. 配置 Git

# 配置用户信息
git config --global user.name "huyixi"
git config --global user.email "[email protected]"

# 生成 SSH Key
ssh-keygen -t ed25519 -C "[email protected]"

# 添加 SSH Key 到 ssh-agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

# 复制公钥到剪贴板
pbcopy < ~/.ssh/id_ed25519.pub

然后去 GitHub -> Settings -> SSH and GPG keys 添加公钥

# 测试 SSH 连接
ssh -T [email protected]

# Git 全局配置
git config --global init.defaultBranch main      # 默认使用 main 分支
git config --global color.ui auto                # 显示颜色
git config --global core.editor "vim"            # 设置默认编辑器
git config --global credential.helper cache      # 缓存 Git 密码(可选)

🐚 5. 安装 Oh My Zsh

# 安装 zsh 插件
brew install zsh-autosuggestions zsh-syntax-highlighting

# 导入 zsh 配置
git clone [email protected]:huyixi/zsh
# 根据需要链接或复制配置文件

👨‍💻 6. 开发环境配置

# Node.js 环境
brew install fnm
# 在 .zshrc 中添加:eval "$(fnm env --use-on-cd --shell zsh)"
fnm install 22
fnm use 22  # 或设为默认版本:fnm default 22
brew install pnpm

# Python 环境
brew install miniconda

# Rust 环境
curl https://sh.rustup.rs -sSf | sh

📦 软件与工具安装

🚀 1. 实用工具

# 安装图片上传工具
brew install bigwig-club/brew/upic --cask

# 安装常用软件
brew install --cask brew google-chrome proxyman iina shottr typora zed stash

🔍 2. Raycast

# 安装 Raycast
brew install --cask raycast

raycast-export

Raycast 导出设置会设置一个默认密码,且无法修改,只能通过设置界面查看。

🔤 3. 字体安装

# 安装霞鹜文楷字体
brew install --cask font-lxgw-wenkai

📝 4. Typora

# 安装 Typora
brew install --cask typora

# 配置 Typora 主题
open ~/Library/Application\ Support/abnerworks.Typora/themes
git clone [email protected]:huyixi/typora-theme.git ~/Library/Application\ Support/abnerworks.Typora/themes

🔄 设置默认应用

#!/bin/bash

# 检查 duti 是否安装
if ! command -v duti &> /dev/null; then
    echo "duti 未安装。请先使用 'brew install duti' 安装 duti。"
    exit 1
fi

# 设置文件类型与应用程序的关联
fileAssociations=(
    # 图片文件
    "com.interversehq.qView jpg"
    "com.interversehq.qView jpeg"
    "com.interversehq.qView png"
    "com.interversehq.qView gif"
    "com.interversehq.qView tiff"
    "com.interversehq.qView bmp"
    "com.interversehq.qView heic"
    # 视频文件
    "com.colliderli.iina mov"
    "com.colliderli.iina mp4"
    "com.colliderli.iina avi"
    "com.colliderli.iina mkv"
    "com.colliderli.iina m4v"
    # 文本文件
    "dev.zed.Zed txt"
    "dev.zed.Zed xml"
    "dev.zed.Zed opml"
    "dev.zed.Zed json"
    "dev.zed.Zed html"
    "dev.zed.Zed css"
    "dev.zed.Zed js"
    "dev.zed.Zed ts"
    "dev.zed.Zed tsx"
    "dev.zed.Zed pub"
    "dev.zed.Zed yaml"
    "dev.zed.Zed csv"
    "abnerworks.Typora md"
    "com.microsoft.Excel xls"
    "com.microsoft.Excel xlsx"
    # PDF 文件
    "com.apple.iBooksX pdf"
)

# 错误日志
errors=()

# 应用设置
echo "正在设置默认应用程序..."
for association in "${fileAssociations[@]}"; do
    app=$(echo "$association" | awk '{print $1}')
    ext=$(echo "$association" | awk '{print $2}')
    echo "设置 .$ext -> $app"
    if ! duti -s "$app" ".$ext" all; then
        # 尝试不带点的扩展名
        if ! duti -s "$app" "$ext" all; then
             errors+=("设置 .$ext 类型的默认应用程序为 $app 失败。")
        fi
    fi
done

# 输出错误日志
if [ ${#errors[@]} -ne 0 ]; then
    echo "------------------------------------------"
    echo "以下文件类型的默认应用程序设置失败:"
    for error in "${errors[@]}"; do
        echo "$error"
    done
    exit 1
else
    echo "------------------------------------------"
    echo "默认应用程序全部设置成功。"
fi

exit 0

📥 修改 Airdrop 默认保存位置

property TARGET_FOLDER : "Macintosh HD:Users:huyixi:Desktop"

property GET_QUARANTINE_COMMAND_START : "ls -l -@ '"
property GET_QUARANTINE_COMMAND_END : "' | tr '\\n' ' ' | sed 's/.*com\\.apple\\.quarantine\\s*\\(\\d*\\)/ \\1/' | awk '{$1=$1};1'"

on adding folder items to this_folder after receiving added_items
	repeat with i from 1 to length of added_items
		set current_item to item i of added_items
		set quarantine_type to getQuarantineType(POSIX path of current_item)
		moveFile(current_item, alias TARGET_FOLDER)
	end repeat
end adding folder items to

on moveFile(move_file, destination_dir)
	tell application "Finder"
		move move_file to destination_dir with replacing
	end tell
end moveFile

on getQuarantineType(file_path)
	return do shell script GET_QUARANTINE_COMMAND_START & file_path & GET_QUARANTINE_COMMAND_END
end getQuarantineType

📚 参考资料