使用 Bash 脚本自动自定义 Mac OS X:27 个默认写入命令、自定义 .aliases、.bash_profile 等

Bash 脚本来自定义许多方面Mac OS X 的

如果您是一名高级用户并且正在设置一台新的 Mac,您可能会使用大量的默认写入命令 和.alias 调整。您可以手动输入这些内容,也可以使用 像 LionTweaks 这样的简单工具 ,或查看这个新的 来自 GitHub 的名为 .osx 的优秀脚本

注意:这显然是为熟悉命令行的更高级用户准备的并了解他们正在做出哪些改变。阅读全文,了解这些调整是否适合您。如果其中任何一项看起来令人困惑,您可能不应该进行这些更改或至少不应该使用此方法,而前面提到的 LionTweaks 实用程序可能更适合。自行承担风险。

选项 1) 完整套件:使用默认写入自定义 .bash_profile、.bash_prompt、.aliases、git 和 Mac OS X

如果您想对 .bash_profile、.aliases、.gitconfig 和所有以下默认写入命令进行大量设置调整,您可以在终端中使用此 git 命令来完成所有操作。在开始这个之前,最好自己检查文件以确保所做的更改是您想要的。

git clone https://github.com/mathiasbynens/dotfiles.git && cd dotfiles && ./bootstrap.sh

.aliases 文件非常有用,但包含一些默认情况下未预安装的命令,如 ngrep,因此您需要自制软件或其他方式来安装这些命令。

选项 2) 默认仅将更改写入 Mac OS X

如果您对所有终端调整和别名不感兴趣,您也可以只获取来自此链接的 .osx 文件

无论哪种情况,在 git 完成后或者您自己获取了 .osx 文件后,您都可以执行脚本:

./.osx

这将立即激活下面列出的所有命令。我们之前已经介绍了几乎所有这些内容,但是在您设置新 Mac 时,将它们放在一个集中的位置并且可以通过 bash 脚本轻松编写是非常有用的。

选项 3:通过输入默认值自己编写命令来选择性地自定义 OS X

这是 .osx 文件中包含的默认写入命令的完整列表,在启动脚本之前查看此命令,或者通过将它们放入终端来选择您要使用的命令:

# 为所有控件启用全键盘访问(例如,在模态对话框中启用 Tab)
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3

# 启用 2D Dock
defaults write com.apple.dock no-glass -bool true

# 禁用菜单栏透明度
defaults write -g AppleEnableMenuBarTransparency -bool false

# 默认展开保存面板
defaults write -g NSNavPanelExpandedStateForSaveMode -bool true

# 默认展开打印面板
defaults write -g PMPrintingExpandedStateForPrint -bool true

# 在屏幕截图中禁用阴影
defaults write com.apple.screencapture disable-shadow -bool true

# 为堆栈的网格视图启用高亮悬停效果(Dock)
defaults write com.apple.dock mouse-over-hilte-stack -bool true

# 为所有 Dock 项目启用 spring 加载
defaults write enable-spring-load-actions-on-all-items -bool true

#禁用按键的按住以支持按键重复
defaults write -g ApplePressAndHoldEnabled -bool false

# 禁用自动更正
默认写入 NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false

# 禁用窗口动画
defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool false

# 禁用磁盘映像验证
defaults write com.apple.frameworks.diskimages skip-verify -bool true
defaults write com.apple.frameworks.diskimages skip-verify -locked -bool true
默认写入 com.apple.frameworks.diskimages skip-verify-remote -bool true

# 挂载卷时自动打开一个新的 Finder 窗口
defaults write com.apple.frameworks.diskimages auto-open-ro-root -bool true
defaults写 com.apple.frameworks.diskimages auto-open-rw-root -bool true

# 避免在网络卷上创建 .DS_Store 文件
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true

# 禁用 Safari 的历史和热门站点的缩略图缓存
defaults write com.apple.Safari DebugSnapshotsUpdatePolicy -int 2

# 启用 Safari 的调试菜单
defaults write com.apple.Safari IncludeDebugMenu -bool true

# 从 Safari 的书签栏中移除无用的图标
defaults write com.apple.Safari ProxiesInBookmarksBar “()”

# 在 Mail.app 中禁用发送和回复动画
defaults write com.apple.Mail DisableReplyAnimations -bool true
defaults write com.apple.Mail DisableSendAnimations -bool true

# Disable Resume system-wide
defaults write NSGlobalDomain NSQuitAlwaysKeepsWindows -bool false

# 启用 Dashboard 开发模式(允许将小部件保留在桌面上)
defaults write com.apple.dashboard devmode -bool true

# Reset Launchpad
rm ~/Library/Application Support/Dock/*.db

# 显示 ~/Library 文件夹
chflags nohidden ~/Library

# 禁用本地 Time Machine 备份
sudo tmutil disablelocal

# Kill 受影响的应用程序
对于 Safari Finder Dock Mail 中的应用程序;做 killall “$app”;完成

# 修复 QuickLook 中古老的 UTF-8 错误 (http://mths.be/bbo)
echo “0x08000100:0” > ~/.CFUserTextEncoding

如果您要进行手动更改,其中许多更改将需要在激活之前重新启动 Finder、Dock 或其他应用程序。这通常是通过脚本使用倒数第二个命令(“杀死受影响的应用程序”)来处理的,但是由于进行了如此多的更改,重新启动 Mac 以确保一切正常工作可能更容易。

感谢 Brian 发送此信息!