-
Notifications
You must be signed in to change notification settings - Fork 0
/
osx_setup
executable file
·181 lines (153 loc) · 7.06 KB
/
osx_setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#/usr/bin/env bash
# vi: set syn=sh :
# Sets up an OS X workstation how I like it.
# TODO: Separate things that need sudo access from those that don't (like Homebrew)
function installDevTools() {
if [[ -e $(xcode-select --print-path) ]]
then
echo "!! XCode command line tools already present."
return
fi
echo "!! Installing XCode command line tools"
xcode-select --install;
echo "!! Sleeping for 10 minutes to allow XCode to install."
sleep 600;
}
function cloneDotfiles() {
if [[ -e $HOME/.dotfiles ]]
then
return
fi
# Clone with the login-free HTTP URL first, then update our local origin URL
git clone https://github.com/nrb/dotfiles.git $HOME/.dotfiles
cd $HOME/.dotfiles
git remote set-url origin [email protected]:nrb/dotfiles.git
}
function installNvimPlugins() {
# vim-plug is downloaded in the nvim init.vim file
# Run plugin installation, then exit
nvim -i NONE +PlugInstall +qa
}
function installHomebrew() {
if [ -e /opt/homebrew/bin/brew ]
then
return
fi
echo "!! Installing Homebrew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(/opt/homebrew/bin/brew shellenv)"
brew doctor
}
function installPrograms() {
brew bundle
# The swift version of dockutil isn't in homebrew, so download it and install it to our home folder so we don't need sudo.
echo "! Installing dockutil"
curl -Lk https://github.com/kcrawford/dockutil/releases/download/3.0.2/dockutil-3.0.2.pkg --silent --output /tmp/dockutil.pkg
installer -pkg /tmp/dockutil.pkg -target CurrentUserHomeDirectory
rm /tmp/dockutil.pkg
}
function cleanDockIcons() {
echo "! Cleaning up default dock icons as of Monterey"
for app in "Launchpad" "Safari" "Messages" "Maps" "Photos" "FaceTime" "Calendar" "Contacts" "Reminders" "Notes" "TV" "Music" "Podcasts" "News" "App Store" "System Preferences" "Downloads" "Keynote" "Numbers" "Pages"; do
dockutil --remove "${app}"
done
}
# A nice defaults command reference:
# http://rixstep.com/2/20060901,00.shtml
function configureDock() {
echo "! Dock to 2D"
defaults write com.apple.dock no-glass -boolean YES
echo "! Dock to bottom corner"
defaults write com.apple.dock pinning -string end
echo "! Disabling dock transparency"
defaults write com.apple.universalaccess reduceTransparency -bool true
echo "! Use the scale effect to minimize"
defaults write com.apple.dock mineffect scale
echo "! Put dock on the right of the screen."
defaults write com.apple.dock orientation -string right;
if [[ $(defaults read com.apple.dock magnification 2> /dev/null) == 0 ]]
then
echo "! Turn off dock zoom"
defaults delete com.apple.dock magnification;
fi
echo "! Show indicator lights in the dock"
defaults write com.apple.dock show-process-indicators -bool true
echo "! Disable dock launch animation"
defaults write com.apple.dock launchanim -bool false
echo "! Automatically show/hide the dock"
defaults write com.apple.dock autohide -bool true
echo "! Restarting Dock"
killall Dock;
}
function configureFinder() {
echo "! Set home dir as default path for new windows."
defaults write com.apple.finder NewWindowTarget -string "PfLo"
defaults write com.apple.finder NewWindowTargetPath -string "file://${HOME}"
echo "! Hiding media from the desktop"
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool false
defaults write com.apple.finder ShowHardDrivesOnDesktop -bool false
defaults write com.apple.finder ShowMountedServersOnDesktop -bool false
defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool false
echo "! Showing full posix path in Finder window title."
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true
echo "! Disabling .DS_Store files on network volumes."
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
echo "! Empty Trash securely by default"
defaults write com.apple.finder EmptyTrashSecurely -bool true
echo "! Showing the ~/Library"
chflags nohidden ~/Library
echo "! Show all file extensions"
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
echo "! Enabling snap-to-grid for icon views"
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :FK_StandardViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
killall Finder;
# Copy email addresses as `[email protected]` instead of `Foo Bar <[email protected]>` in Mail.app
defaults write com.apple.mail AddressesIncludeNameOnPasteboard -bool false
}
# taken from https://gist.github.com/thomasfinch/14bd3181799734c872d2ad3b207cc01c
function configureNightShift() {
echo "! Enabling Night Shift"
plistLoc="/private/var/root/Library/Preferences/com.apple.CoreBrightness.plist"
currentUserUID=$(dscl . -read /Users/$(whoami)/ GeneratedUID) # Get the GeneratedUID for the current user
currentUserUID=$(echo $currentUserUID | cut -d' ' -f2) # Remove the "GeneratedUID: " part
currentUserUID="CBUser-"$currentUserUID # Append the prefix
# Enable settings
algoOverride=4
enabled=1
# Change the settings directly in the core brightness plist (defaults doesn't deal with nested data structures well)
sudo /usr/libexec/PlistBuddy -c "Set :$currentUserUID:CBBlueReductionStatus:BlueLightReductionAlgoOverride $algoOverride" $plistLoc
sudo /usr/libexec/PlistBuddy -c "Set :$currentUserUID:CBBlueReductionStatus:BlueReductionEnabled $enabled" $plistLoc
sudo /usr/libexec/PlistBuddy -c "Set :$currentUserUID:CBBlueReductionStatus:BlueLightReductionAlgoOverrideTimestamp `date`" $plistLoc
}
function main() {
if ! [[ "$OSTYPE" =~ ^darwin ]];
then
echo "ERROR: This script must be run under OS X."
exit 1
fi
installDevTools
cloneDotfiles
installHomebrew
installPrograms
installNvimPlugins
configureDock
cleanDockIcons
configureFinder
configureNightShift
echo "! Configuring Activity Monitor"
# Show the main window when launching Activity Monitor
defaults write com.apple.ActivityMonitor OpenMainWindow -bool true
# Show all processes in Activity Monitor
defaults write com.apple.ActivityMonitor ShowCategory -int 0
# Disable smart quotes as they’re annoying when typing code
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
# Disable smart dashes as they’re annoying when typing code
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
# Prettier fonts, per alacritty docs.
defaults write -g AppleFontSmoothing -int 0
echo "! Setting timezone (sudo)"
sudo systemsetup -settimezone "America/New York" > /dev/null
}
main "$@"