#!/bin/bash
sudo -v
# Yêu cầu quyền
if [[ $EUID -ne 0 ]]; then
   echo "Vui lòng chạy bằng sudo!"
   exit 1
fi

echo "Đang áp dụng thiết lập hệ thống..."

########## TẮT GÕ TẮT / SỬA CHÍNH TẢ / GỢI Ý ##########
defaults write NSGlobalDomain NSAutomaticTextReplacementEnabled -bool false
defaults write -g WebAutomaticTextReplacementEnabled -bool false
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
defaults write NSGlobalDomain NSAutomaticTextCompletionEnabled -bool false
defaults write NSGlobalDomain NSAutomaticCapitalizationEnabled -bool false
defaults write NSGlobalDomain NSAutomaticPeriodSubstitutionEnabled -bool false
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
defaults write -g NSAllowContinuousSpellChecking -bool false
defaults write -g NSAutomaticSpellingCorrectionEnabled -bool false
defaults write -g NSAutomaticTextCompletionEnabled -bool false
defaults write NSGlobalDomain NSSpellCheckerAutomaticallyIdentifiesLanguages -bool false

killall cfprefsd 2>/dev/null

########## KHÓA DOCK ##########
defaults write com.apple.dock position-immutable -bool true
defaults write com.apple.dock contents-immutable -bool true
defaults write com.apple.dock size-immutable -bool true
defaults write com.apple.dock autohide-immutable -bool true

########## FINDER SETTINGS ##########
# Tắt cảnh báo đổi phần mở rộng file
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false

# Không tạo DS_Store trên USB / Network
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true

# Chế độ xem mặc định: List view
defaults write com.apple.finder FXPreferredViewStyle Nlsv
defaults write com.apple.Finder FXPreferredViewStyle -string "Nlsv"

# Duyệt trong chế độ xem danh sách
defaults write com.apple.Finder FXPreferredSearchViewStyle -string "Nlsv"

# Auto arrange theo Name
defaults write com.apple.finder FXPreferredGroupBy -string "Name"

# Tính dung lượng thư mục trong List view
defaults write com.apple.finder CalculateAllSizes -bool true

# Hiển thị thanh trạng thái & path
defaults write com.apple.finder ShowStatusBar -bool true
defaults write com.apple.finder ShowPathbar -bool true

########## KHÁC ##########
# Tắt badge Recent trên Dock
defaults write com.apple.dock show-recents -bool false

# Tắt Resume khi khởi động lại
defaults write NSGlobalDomain NSQuitAlwaysKeepsWindows -bool false

########## RESTART ##########
killall Finder 2>/dev/null
killall Dock 2>/dev/null

echo "Hoàn tất!"