-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1_macos_config_script
473 lines (362 loc) · 21.6 KB
/
1_macos_config_script
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
#!/usr/bin/env bash
# ~/.macos — adapted from https://mths.be/macos
# there are many more settings in that file, i've removed some that are anyway the default, I see the point in including them
# (in case source is not at default, or macos change the default), however the script is very large and unmanagable, and in principle
# I just wanted to change settings that need changing
# Also beware because this is not a fork, and many contributors are contributing there, this file will now need manually checking against that one
# basic principles of this: https://pawelgrzybek.com/change-macos-user-preferences-via-command-line/
# an easy way to determine config keys yourself is:
# defaults read > before
# then make your change in system preferences etc
# defaults read > after
# diff before after
# Close any open System Preferences panes, to prevent them from overriding settings we’re about to change
osascript -e 'tell application "System Preferences" to quit'
# Ask for the administrator password upfront
sudo -v
# Keep-alive: update existing `sudo` time stamp until `.macos` has finished
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
###############################################################################
# General UI/UX #
###############################################################################
echo "MacOS Auto-Configuration script"
echo ""
# We will change your computername in lots of places.....
echo "scutil currently says LocalHostName: $(scutil --get LocalHostName) , ComputerName: $(scutil --get ComputerName) , HostName: $(scutil --get HostName)"
read -p "Enter the computername to use (or nothing to continue with current name):" computername
if [[ -z "$computername" ]]; then
echo "you didn't type anything, so keeping current computername and continuing"
else
read -p "you typed $computername - are you happy with that? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || ( echo "youre not happy with the name you chose...best to exit..." && exit 1 )
# Set computer name (as done via System Preferences → Sharing)
sudo scutil --set ComputerName "$computername"
sudo scutil --set HostName "$computername"
sudo scutil --set LocalHostName "$computername"
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string "$computername"
fi
# Set sidebar icon size to medium
defaults write NSGlobalDomain NSTableViewDefaultSizeMode -int 2
# Save to disk (not to iCloud) by default
defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false
# Disable the “Are you sure you want to open this application?” dialog
defaults write com.apple.LaunchServices LSQuarantine -bool false
# Remove duplicates in the “Open With” menu (also see `lscleanup` alias)
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user
# Display ASCII control characters using caret notation in standard text views
# Try e.g. `cd /tmp; unidecode "\x{0000}" > cc.txt; open -e cc.txt`
defaults write NSGlobalDomain NSTextShowsControlCharacters -bool true
# Disable Notification Center and remove the menu bar icon (not working for me!)
launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist 2> /dev/null
# put the date in the menu bar with the time
# see here https://www.tech-otaku.com/mac/setting-the-date-and-time-format-for-the-macos-menu-bar-clock-using-terminal/
defaults write com.apple.menuextra.clock DateFormat -string "d MMM h:mm"
###############################################################################
# Trackpad, mouse, keyboard, Bluetooth accessories, and input #
###############################################################################
# Trackpad: enable tap to click for this user and for the login screen
#defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true
#defaults -currentHost write NSGlobalDomain com.apple.mouse.tapBehavior -int 1
#defaults write NSGlobalDomain com.apple.mouse.tapBehavior -int 1
# Trackpad: map bottom right corner to right-click
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadCornerSecondaryClick -int 2
# something very odd here, mattias' values were -bool true, which seems sensible, however they didnt
# work, and a before/after diff showed the values were set to false!?!
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadRightClick -bool false
defaults write com.apple.driver.AppleMultitouch.trackpad TrackpadRightClick -bool false
defaults -currentHost write NSGlobalDomain com.apple.trackpad.trackpadCornerClickBehavior -int 1
defaults -currentHost write NSGlobalDomain com.apple.trackpad.enableSecondaryClick -bool true
# Disable “natural” (Lion-style) scrolling
defaults write NSGlobalDomain com.apple.swipescrolldirection -bool false
# Enable full keyboard access for all controls
# (e.g. enable Tab in modal dialogs)
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
# Disable press-and-hold for keys in favor of key repeat
# this is mathias' default, previously I had instructed to do this with boostnote and vscode individually:
# defaults write com.electron.boostnote ApplePressAndHoldEnabled -bool false
# defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false
# so let's just do it systemwide
#
# if you need to go back to individual apps you can work out their identifiers with e.g.: defaults domains | gsed -e 's/, /\n/g' | grep jetbrains
# (see https://www.lorrin.org/blog/2012/03/02/fixing-key-repeat-in-os-x-lion-and-restoring-sanity-for-vim-keybindings-on-a-per-application-basis/comment-page-1/)
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false
# Set a blazingly fast keyboard repeat rate
# https://apple.stackexchange.com/a/288764 - The defaults for a freshly installed macOS Sierra 10.12.5 (16F73) are: InitialKeyRepeat = 25 and KeyRepeat = 6
# The step values that correspond to the sliders on the GUI are as follow (lower equals faster): System Prefs > Keyboard > Delay Until Repeat
# KeyRepeat: 120, 90, 60, 30, 12, 6, 2 InitialKeyRepeat: 120, 94, 68, 35, 25, 15
defaults write NSGlobalDomain KeyRepeat -int 1
defaults write NSGlobalDomain InitialKeyRepeat -int 10
###############################################################################
# Energy saving #
###############################################################################
# https://apple.stackexchange.com/a/131882
# pmset -g to show the default settings
# if you want to go back to the defaults pmset -c 2 -b 1 -u 1; pmset -g
# (You can confirm these are the defaults after running the command by opening System Preferences > Energy Saver and seeing that the
# "Restore to Defaults" option is greyed out
# on typhoon, these were the pmset defaults on charge
# % pmset -g
# System-wide power settings:
# Currently in use:
# standbydelaylow 10800
# standby 1
# womp 1
# halfdim 1
# hibernatefile /var/vm/sleepimage
# proximitywake 1
# powernap 1
# gpuswitch 2
# networkoversleep 0
# disksleep 10
# standbydelayhigh 86400
# sleep 1 (sleep prevented by sharingd)
# hibernatemode 3
# ttyskeepawake 1
# displaysleep 10
# tcpkeepalive 1
# highstandbythreshold 50
# acwake 0
# lidwake 1
# and on battery:
# System-wide power settings:
# Currently in use:
# standbydelaylow 10800
# standby 1
# halfdim 1
# hibernatefile /var/vm/sleepimage
# proximitywake 0
# powernap 0
# gpuswitch 2
# disksleep 10
# standbydelayhigh 86400
# sleep 1 (sleep prevented by sharingd)
# hibernatemode 3
# ttyskeepawake 1
# displaysleep 2
# tcpkeepalive 1
# highstandbythreshold 50
# acwake 0
# lidwake 1
# Sleep the display after 15 minutes on charge (default is 10)
sudo pmset -c displaysleep 15
# Sleep the display after 5 minutes on battery (default is 2)
sudo pmset -b displaysleep 5
# Set machine sleep to 5 minutes on battery
#sudo pmset -b sleep 5
# show percentage in menu bar battery icon
defaults write com.apple.menuextra.battery ShowPercent YES
# auto-hide menu bar
defaults write NSGlobalDomain _HIHideMenuBar -bool true
###############################################################################
# Screen #
###############################################################################
# Enable subpixel font rendering on non-Apple LCDs
# Reference: https://github.com/kevinSuttle/macOS-Defaults/issues/17#issuecomment-266633501
#defaults write NSGlobalDomain AppleFontSmoothing -int 1
# Enable HiDPI display modes (requires restart)
#sudo defaults write /Library/Preferences/com.apple.windowserver DisplayResolutionEnabled -bool true
###############################################################################
# Finder #
###############################################################################
# Finder: allow quitting via ⌘ + Q; doing so will also hide desktop icons
defaults write com.apple.finder QuitMenuItem -bool true
# Set Home as the default location for new Finder windows (note mattias had Desktop)
# For other paths, use `PfLo` and `file:///full/path/here/`
defaults write com.apple.finder NewWindowTarget -string "PfHm"
defaults write com.apple.finder NewWindowTargetPath -string "file://${HOME}/"
# Show icons for hard drives, servers, and removable media on the desktop
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true
defaults write com.apple.finder ShowHardDrivesOnDesktop -bool true
defaults write com.apple.finder ShowMountedServersOnDesktop -bool true
defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true
# Finder: show hidden files by default
defaults write com.apple.finder AppleShowAllFiles -bool true
# Finder: show all filename extensions
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
# Finder: show status bar
defaults write com.apple.finder ShowStatusBar -bool true
# Finder: show path bar
defaults write com.apple.finder ShowPathbar -bool true
# Display full POSIX path as Finder window title
# handy to see where we are if nothing else, also a little like windows explorer paths...
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true
# Keep folders on top when sorting by name
#defaults write com.apple.finder _FXSortFoldersFirst -bool true
# When performing a search, search the current folder by default (default is whole mac)
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"
# Disable the warning when changing a file extension
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
# Avoid creating .DS_Store files on network or USB volumes
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
# Show item info near icons on the desktop and in other icon views
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:showItemInfo true" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :FK_StandardViewSettings:IconViewSettings:showItemInfo true" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:showItemInfo true" ~/Library/Preferences/com.apple.finder.plist
# Show item info to the right of the icons on the desktop
#/usr/libexec/PlistBuddy -c "Set DesktopViewSettings:IconViewSettings:labelOnBottom false" ~/Library/Preferences/com.apple.finder.plist
# Use list view in all Finder windows by default
# Four-letter codes for the other view modes: `icnv`, `clmv`, `glyv`
defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv"
# Disable the warning before emptying the Trash
#defaults write com.apple.finder WarnOnEmptyTrash -bool false
# Show the ~/Library folder
chflags nohidden ~/Library # "no such xattr in catalina" && xattr -d com.apple.FinderInfo ~/Library
# Show the /Volumes folder
sudo chflags nohidden /Volumes
# Expand the following File Info panes:
# “General”, “Open with”, and “Sharing & Permissions”
#defaults write com.apple.finder FXInfoPanesExpanded -dict \
# General -bool true \
# OpenWith -bool true \
# Privileges -bool true
###############################################################################
# Dock, Dashboard, and hot corners #
###############################################################################
# Enable highlight hover effect for the grid view of a stack (Dock)
defaults write com.apple.dock mouse-over-hilite-stack -bool true
# Set the icon size of Dock items to 36 pixels (default is 64)
defaults write com.apple.dock tilesize -int 36
# Minimize windows into their application’s icon (actually i like minimising to right of dock, however i don't remember making use of...)
#defaults write com.apple.dock minimize-to-application -bool true
# Enable spring loading for all Dock items - default is false - hover over dock icon with a file and app/folder will open
defaults write com.apple.dock enable-spring-load-actions-on-all-items -bool true
# Wipe all (default) app icons from the Dock
# This is only really useful when setting up a new Mac, or if you don’t use
# the Dock to launch apps.
#defaults write com.apple.dock persistent-apps -array
# Don’t automatically rearrange Spaces based on most recent use
#defaults write com.apple.dock mru-spaces -bool false
# Remove the auto-hiding Dock delay
#defaults write com.apple.dock autohide-delay -float 0
# Remove the animation when hiding/showing the Dock
#defaults write com.apple.dock autohide-time-modifier -float 0
# Automatically hide and show the Dock
defaults write com.apple.dock autohide -bool true
# Make Dock icons of hidden applications translucent
defaults write com.apple.dock showhidden -bool true
# Don’t show recent applications in Dock
#defaults write com.apple.dock show-recents -bool false
###############################################################################
# Terminal & iTerm 2 #
###############################################################################
# Only use UTF-8 in Terminal.app
defaults write com.apple.terminal StringEncodings -array 4
# Use a modified version of the Solarized Dark theme by default in Terminal.app
# Mattias' script tries to set solarized as the terminal theme for all terminals, but it doesn't try to get it! try to download the latest solarized
echo "trying to download the latest solarized package (then i'll try to open it with terminal....later you can do so with iterm2)"
curl -fLo ~/Downloads/solarized.zip https://github.com/altercation/solarized/archive/master.zip && unzip -oq ~/Downloads/solarized.zip -d ~/Downloads/
echo "trying to open the solarized terminal theme in terminal (you'll need to close the terminal it opens to continue...."
themeFile=/Users/twoode/Downloads/solarized-master/osx-terminal.app-colors-solarized/xterm-256color/Solarized\ Dark\ xterm-256color.terminal
echo "Tried to download the latest solarized package to ~/Downloads - we'll open to effect a double click on /Users/twoode/Downloads/solarized-master/osx-terminal.app-colors-solarized/xterm-256color/Solarized\ Dark\ xterm-256color.terminal"
osascript <<EOD
tell application "Terminal"
local allOpenedWindows
local initialOpenedWindows
local windowID
set themeName to "Solarized Dark xterm-256color"
(* Store the IDs of all the open terminal windows. *)
set initialOpenedWindows to id of every window
(* Open the custom theme so that it gets added to the list
of available terminal themes (note: this will open two
additional terminal windows). *)
do shell script "open '$themeFile'"
(* Wait a little bit to ensure that the custom theme is added. *)
delay 1
(* Set the custom theme as the default terminal theme. *)
set default settings to settings set themeName
(* Get the IDs of all the currently opened terminal windows. *)
set allOpenedWindows to id of every window
repeat with windowID in allOpenedWindows
(* Close the additional windows that were opened in order
to add the custom theme to the list of terminal themes. *)
if initialOpenedWindows does not contain windowID then
close (every window whose id is windowID)
(* Change the theme for the initial opened terminal windows
to remove the need to close them in order for the custom
theme to be applied. *)
else
set current settings of tabs of (every window whose id is windowID) to settings set themeName
end if
end repeat
end tell
EOD
# Enable Secure Keyboard Entry in Terminal.app
# See: https://security.stackexchange.com/a/47786/8918
#defaults write com.apple.terminal SecureKeyboardEntry -bool true
# Disable the annoying line marks
#defaults write com.apple.Terminal ShowLineMarks -int 0
# Install the Solarized Dark theme for iTerm
# i could mod this to work with the solarized dsownload above, but the problem is we may not have iterm yet!
#open "${HOME}/init/Solarized Dark.itermcolors"
# Don’t display the annoying prompt when quitting iTerm
#defaults write com.googlecode.iterm2 PromptOnQuit -bool false
###############################################################################
# Security #
###############################################################################
# enable the firewall - see https://coderwall.com/p/zt8aqa/disable-mac-osx-firewall-from-command-line
# however, SIP prevents us from unloading the firewall service so a restart prob needed here
sudo defaults write /Library/Preferences/com.apple.alf globalstate -int 1
###############################################################################
# Time Machine #
###############################################################################
# Prevent Time Machine from prompting to use new hard drives as backup volume
defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true
# Disable local Time Machine backups - see discussions.apple.com/8612572 - looks like they removed this key
# hash tmutil &> /dev/null && sudo tmutil disablelocal
###############################################################################
# Activity Monitor #
###############################################################################
# Show the main window when launching Activity Monitor
defaults write com.apple.ActivityMonitor OpenMainWindow -bool true
# Visualize CPU usage in the Activity Monitor Dock icon
defaults write com.apple.ActivityMonitor IconType -int 5
# Show all processes in Activity Monitor
defaults write com.apple.ActivityMonitor ShowCategory -int 0
# Sort Activity Monitor results by CPU usage
defaults write com.apple.ActivityMonitor SortColumn -string "CPUUsage"
defaults write com.apple.ActivityMonitor SortDirection -int 0
###############################################################################
# Address Book, Dashboard, iCal, TextEdit, and Disk Utility #
###############################################################################
# Use plain text mode for new TextEdit documents
defaults write com.apple.TextEdit RichText -int 0
# Open and save files as UTF-8 in TextEdit
defaults write com.apple.TextEdit PlainTextEncoding -int 4
defaults write com.apple.TextEdit PlainTextEncodingForWrite -int 4
###############################################################################
# Mac App Store #
###############################################################################
# Check for software updates daily, not just once per week
#defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1
# Automatically download apps purchased on other Macs
# think i'd rather have my mas script do this....
# defaults write com.apple.SoftwareUpdate ConfigDataInstall -int 1
# Turn on app auto-update
# i discovered that catalina needs your password to change this setting in-app, but if you change it here it doesn't but the setting 'sticks' until you issue a false here
defaults write com.apple.commerce AutoUpdate -bool true
###############################################################################
# Photos #
###############################################################################
# Prevent Photos from opening automatically when devices are plugged in
defaults -currentHost write com.apple.ImageCapture disableHotPlug -bool true
###############################################################################
# Kill affected applications #
###############################################################################
read -s -n 1 -p "All configs set, press a key to restart affected applications (including finder) (you prob have to restart for all settings to change though)"
for app in "Activity Monitor" \
"Address Book" \
"Calendar" \
"cfprefsd" \
"Contacts" \
"Dock" \
"Finder" \
"Mail" \
"Messages" \
"Photos" \
"Safari" \
"SystemUIServer" \
"Terminal" \
"iCal"; do
killall "${app}" &> /dev/null
done
echo "Done. Note that some of these changes require a logout/restart to take effect."