#!/bin/bash
set -e
set -u
# 参考:
# - https://github.com/rootbeersoup/dotfiles
# - https://github.com/skwp/dotfiles
# - https://github.com/sobolevn/dotfiles
# - https://github.com/webpro/dotfiles
# - https://apple.stackexchange.com/questions/14001/how-to-turn-off-all-animations-on-os-x
echo 'Macを設定しています。少々お待ちください。'
osascript -e 'tell application "System Preferences" to quit'
## 一般 ##
# 起動時の効果音を無効化
sudo nvram SystemAudioVolume=" "
sudo nvram StartupMute=%01
# 「このアプリケーションを開いてもよろしいですか?」ダイアログを無効化
defaults write com.apple.LaunchServices LSQuarantine -bool false
# 通知を無効化
launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist
## キーボード
# CapsLock遅延を無効化
hidutil property --set '{"CapsLockDelayOverride":0}'
# リピート入力認識までの時間: 15 (225ms) とキーのリピート速度: 2 (30ms)
# 値が小さいほど高速になる
defaults write -g InitialKeyRepeat -int 15
defaults write -g KeyRepeat -int 2
## トラックパッド
# カーソル速度: 5(範囲: 0-3が標準、それ以上は高速)
defaults write -g com.apple.trackpad.scaling 5
## Dock ##
# Dockのアプリケーション側にある項目の配列を削除(既存のアプリをすべて削除)
defaults delete com.apple.dock persistent-apps
# Dockの書類側にある項目の配列を削除
defaults delete com.apple.dock persistent-others
# 起動中インジケーター(アイコン下の点)を無効化
defaults write com.apple.dock show-process-indicators -bool false
defaults write com.apple.dock show-recents -bool false
# Dockの自動非表示アニメーション速度: 0(即座に表示/非表示)
defaults write com.apple.dock autohide-time-modifier -int 0
# Dock内のアイコンサイズを43ピクセルに変更(デフォルトは64)
defaults write com.apple.dock "tilesize" -int 43
# お気に入りアプリをDockに追加
apps=("/System/Applications/System Settings" "/System/Applications/Utilities/Terminal" "/Applications/CotEditor" "/Applications/Visual Studio Code" "/Applications/Google Chrome" "/Applications/Firefox" "/Applications/Zotero" "/System/Applications/Mail")
for app in "${apps[@]}"
do
defaults write com.apple.dock persistent-apps -array-add "<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>$app.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"
done
## Finder ##
# 名前順にソートする際、フォルダを上部に表示
defaults write com.apple.finder _FXSortFoldersFirst -bool true
# Finderのパスバーを表示
defaults write com.apple.finder ShowPathbar -bool true
# Finderのステータスバーを非表示
defaults write com.apple.finder ShowStatusBar -bool false
# Finderで隠しファイルを表示(手動切替: cmd + shift + .)
defaults write com.apple.finder AppleShowAllFiles -bool true
# Finderでファイル拡張子を表示
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
# ファイル拡張子変更時の警告を無効化
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
# 未確認のアプリを開く際の警告を無効化
defaults write com.apple.LaunchServices LSQuarantine -bool false
# すべてのFinderウィンドウでカラムビューをデフォルトに設定
# 表示モード:
# Flwv - Cover Flowビュー
# Nlsv - リストビュー
# clmv - カラムビュー
# icnv - アイコンビュー
defaults write com.apple.finder FXPreferredViewStyle -string "clmv"
# .DS_Storeファイルの作成を回避(ネットワークドライブとUSBドライブ)
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
# すべての.txtファイルのデフォルトエディタをCotEditorに設定
defaults write com.apple.LaunchServices LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.coteditor.CotEditor;}'
# スプリングローディング(ファイルをドラッグ中にフォルダ上でホバーすると開く機能)
# 遅延を0秒に設定(即座に開く)
defaults write NSGlobalDomain com.apple.springing.delay -float 0
# Libraryフォルダを表示
chflags nohidden ~/Library
## その他 ##
# Launchpadの表示/非表示アニメーション速度: 0(即座に表示/非表示)
defaults write com.apple.dock springboard-show-duration -float 0
defaults write com.apple.dock springboard-hide-duration -float 0
# メニューバーのアイコン間隔を6ピクセルに変更(デフォルトより狭く)
defaults -currentHost write -globalDomain NSStatusItemSpacing -int 6
## スクリーンショット ##
defaults write com.apple.screencapture name "screenshot"
defaults write com.apple.screencapture show-thumbnail -bool false # サムネイルプレビューを非表示
defaults write com.apple.screencapture include-date -bool false # ファイル名に日付を含めない
defaults write com.apple.screencapture disable-shadow -bool true # ウィンドウの影を無効化
defaults write com.apple.screencapture showsCursor -bool true # カーソルを表示
defaults write com.apple.screencapture location ~/Desktop/ # 保存先: デスクトップ
defaults write com.apple.screencapture type png # ファイル形式: PNG(他: gif, jpeg, pdf, bmp, tiff, psd, jpeg 2000など)
# defaults read com.apple.screencapture # スクリーンショットに関するすべての設定を確認
## アプリの再起動 ##
echo 'アプリを再起動しています...'
killall Finder
killall Dock
echo '完了!'