forked from nnja/new-computer
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.sh
executable file
·801 lines (664 loc) · 31.3 KB
/
setup.sh
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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
#!/bin/sh
# _ _ _ _
# ___ _____ __ (_)_ __ ___| |_ __ _| | |
# / _ \/ __\ \/ / | | '_ \/ __| __/ _` | | |
#| (_) \__ \> < | | | | \__ \ || (_| | | |
# \___/|___/_/\_\ |_|_| |_|___/\__\__,_|_|_|
echo "Setting things up just the way I like them..."
# Based on:
# https://github.com/nnja/new-computer
# Some configs reused from:
# https://github.com/ruyadorno/installme-osx/
# https://gist.github.com/millermedeiros/6615994
# https://gist.github.com/brandonb927/3195465/
# https://github.com/mjording/dotfiles/blob/master/osx
# Colorize
# Set the colours you can use
black=$(tput setaf 0)
red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
blue=$(tput setaf 4)
magenta=$(tput setaf 5)
cyan=$(tput setaf 6)
white=$(tput setaf 7)
# Resets the style
reset=`tput sgr0`
# Color-echo. Improved. [Thanks @joaocunha]
# arg $1 = message
# arg $2 = Color
cecho() {
echo "${2}${1}${reset}"
return
}
echo ""
cecho "###############################################" $red
cecho "# DO NOT RUN THIS SCRIPT BLINDLY #" $red
cecho "# YOU'LL PROBABLY REGRET IT... #" $red
cecho "# #" $red
cecho "# READ IT THOROUGHLY #" $red
cecho "# AND EDIT TO SUIT YOUR NEEDS #" $red
cecho "###############################################" $red
echo ""
# Set continue to false by default.
CONTINUE=true
echo ""
cecho "Have you read through the script you're about to run and " $red
cecho "understood that it will make changes to your computer? (y/n)" $red
read -r response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
CONTINUE=true
fi
if ! $CONTINUE; then
# Check if we're continuing and output a message if not
cecho "Please go read the script, it only takes a few minutes" $red
exit
fi
# Here we go.. ask for the administrator password upfront and run a
# keep-alive to update existing `sudo` time stamp until script has finished
sudo -v
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
##############################
# General
##############################
# Set computer name (as done via System Preferences → Sharing)
read -p 'Name this computer: ' hostName
sudo scutil --set ComputerName $hostName
sudo scutil --set HostName $hostName
sudo scutil --set LocalHostName $hostName
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string $hostName
# Menu bar: show remaining battery %
# this file is named with a hostid that varies by installation, there should only be one file that matches this loop
# this also seems to require a restart. it's not updated by terminating SystemUIServer, or Control Center, or Finder.
for plist in ~/Library/Preferences/ByHost/com.apple.controlcenter.*.plist; do
plutil -replace BatteryShowPercentage -integer 1 "$plist"
done
##############################
# Prerequisite: Install Brew #
##############################
echo "Installing brew..."
if test ! $(which brew)
then
## Don't prompt for confirmation when installing homebrew
# /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
# Latest brew, install brew
brew upgrade
brew update
# not necessary anymore
#brew tap homebrew/cask
#############################################
### Generate ssh keys & add to ssh-agent
### See: https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/
#############################################
echo "Generating ssh keys, adding to ssh-agent..."
read -p 'Input email for ssh key: ' useremail
echo "Use default ssh file location, enter a passphrase: "
ssh-keygen -t rsa -b 4096 -C "$useremail" # will prompt for password
eval "$(ssh-agent -s)"
# Now that sshconfig is synced add key to ssh-agent and
# store passphrase in keychain
ssh-add -K ~/.ssh/id_rsa
# If you're using macOS Sierra 10.12.2 or later, you will need to modify your ~/.ssh/config file to automatically load keys into the ssh-agent and store passphrases in your keychain.
if [ -e ~/.ssh/config ]
then
echo "ssh config already exists. Skipping adding osx specific settings... "
else
echo "Writing osx specific settings to ssh config... "
cat <<EOT >> ~/.ssh/config
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
EOT
fi
#############################################
### Add ssh-key to GitHub via api
#############################################
echo "Adding ssh-key to GitHub (via api)..."
echo "Important! For this step, use a github personal token with the admin:public_key permission."
echo "If you don't have one, create it here: https://github.com/settings/tokens/new"
retries=3
SSH_KEY=`cat ~/.ssh/id_rsa.pub`
for ((i=0; i<retries; i++)); do
read -p 'GitHub username: ' ghusername
read -sp 'GitHub personal token: ' ghtoken
gh_status_code=$(curl -o /dev/null -s -w "%{http_code}\n" -u "$ghusername:$ghtoken" -d '{"title":"'$hostName'","key":"'"$SSH_KEY"'"}' 'https://api.github.com/user/keys')
if (( $gh_status_code -eq == 201))
then
echo "GitHub ssh key added successfully!"
break
else
echo "Something went wrong. Enter your credentials and try again..."
echo -n "Status code returned: "
echo $gh_status_code
fi
done
[[ $retries -eq i ]] && echo "Adding ssh-key to GitHub failed! Try again later."
#############################################
### Setup git user info
#############################################
read -p 'Git email address: ' gitEmail
read -p 'Git name: ' gitName
git config --global user.email "$gitEmail"
git config --global user.name "$gitName"
##############################
# Install via Brew #
##############################
echo "Starting brew app install..."
### Developer Tools
#brew cask install iterm2
#brew cask install dash
brew install node
brew install yarn
brew install orbstack
brew install docker
#brew install virtualbox
#brew install awscli
#npm i -g --no-optional gatsby-cli
#npm install -g @aws-amplify/cli@multienv
### Command line tools - install new ones, update others to latest version
brew install git # upgrade to latest
brew install tmux
#brew link curl --force
brew install trash # move to osx trash instead of rm
brew install less
### Dev Editors
brew install visual-studio-code
#brew install phpstorm #installs 2018.x
brew install --cask jetbrains-toolbox
brew install textmate
### Browsers
brew install google-chrome
brew install firefox
brew install brave-browser
### Productivity
#brew cask install alfred
brew install dropbox
brew install rectangle # replaced spectacle
brew install hiddenbar # replaced bartender
brew install slack
### Quicklook plugins https://github.com/sindresorhus/quick-look-plugins
#brew cask install qlcolorcode # syntax highlighting in preview
#brew cask install qlstephen # preview plaintext files without extension
#brew cask install qlmarkdown # preview markdown files
#brew cask install quicklook-json # preview json files
#brew cask install epubquicklook # preview epubs, make nice icons
#brew cask install quicklook-csv # preview csvs
# Utilities
#brew cask install homebrew/cask-drivers/drobo-dashboard
### Run Brew Cleanup
brew cleanup
### Fix Dock
brew install dockutil
dockutil --remove Launchpad --no-restart
dockutil --remove Messages --no-restart
dockutil --remove Mail --no-restart
dockutil --remove Maps --no-restart
dockutil --remove Photos --no-restart
dockutil --remove FaceTime --no-restart
dockutil --remove Contacts --no-restart
dockutil --remove Reminders --no-restart
dockutil --remove Notes --no-restart
dockutil --remove Freeform --no-restart
dockutil --remove TV --no-restart
dockutil --remove Music --no-restart
dockutil --remove News --no-restart
dockutil --remove Siri --no-restart
dockutil --remove iTunes --no-restart
dockutil --remove Keynote --no-restart
dockutil --remove Numbers --no-restart
dockutil --remove Pages --no-restart
dockutil --remove App\ Store --no-restart
dockutil --add /Applications/Google\ Chrome.app --after Safari --no-restart
dockutil --add /Applications/Firefox.app --after Google\ Chrome --no-restart
dockutil --add /Applications/Brave\ Browser.app --after Firefox--no-restart
dockutil --add /Applications/Visual\ Studio\ Code.app --after Brave\ Browser --no-restart
dockutil --add /Applications/Utilities/Terminal.app --after Firefox --no-restart
#dockutil --add /Applications/iTerm.app --after Terminal --no-restart
dockutil --add /Applications/Utilities/Disk\ Utility.app --after Terminal --no-restart
dockutil --add /Applications/Utilities/Activity\ Monitor.app --after "Disk Utility" --no-restart
dockutil --add /Applications/TextMate --after "Activity Monitor"
### make sure the last dockutil call does not have --no-restart
#############################################
### Installs from Mac App Store
#############################################
#echo "Installing apps from the App Store..."
### find app ids with: mas search "app name"
brew install mas
### Mas login is currently broken on mojave. See:
### Login manually for now.
cecho "Need to log in to App Store manually to install apps with mas...." $red
echo "Opening App Store. Please login."
open "/Applications/App Store.app"
echo "Is app store login complete.(y/n)? "
read response
if [ "$response" != "${response#[Yy]}" ]
then
mas install 497799835 # xcode
else
cecho "App Store login not complete. Skipping installing App Store Apps" $red
fi
#############################################
### Set OSX Preferences - Borrowed from https://github.com/mathiasbynens/dotfiles/blob/master/.macos
#############################################
# xcode license
sudo xcodebuild -license accept
# fix xcodebuild on command line
# see: https://stackoverflow.com/questions/17980759/xcode-select-active-developer-directory-error/17980786#17980786
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
# 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'
###############################################################################
# Finder, Dock, & Menu Items #
###############################################################################
# Finder: allow quitting via ⌘ + Q; doing so will also hide desktop icons
defaults write com.apple.finder QuitMenuItem -bool true
# Expand save panel by default
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool true
# Save to disk (not to iCloud) by default
defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false
# Finder: show all filename extensions
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
# Finder: show hard drives on desktop
defaults write com.apple.finder ShowHardDrivesOnDesktop -int 1
# Shrink dock icons
defaults write com.apple.dock tilesize -int 45
# Display full POSIX path as Finder window title
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true
# Disable the warning when changing a file extension
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
# Automatically quit printer app once the print jobs complete
defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true
# Disable the “Are you sure you want to open this application?” dialog
#defaults write com.apple.LaunchServices LSQuarantine -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
# Use list view in all Finder windows by default
# Four-letter codes for the other view modes: `icnv`, `clmv`, `Flwv`
defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv"
# Minimize windows into their application’s icon
defaults write com.apple.dock minimize-to-application -bool true
# Don’t show recent applications in Dock
defaults write com.apple.dock show-recents -bool false
# Show the ~/Library folder
chflags nohidden ~/Library
# Finder: show hidden files by default
defaults write com.apple.finder AppleShowAllFiles -bool true
# Finder: allow text selection in Quick Look
defaults write com.apple.finder QLEnableTextSelection -bool true
# Enable snap-to-grid for icons on the desktop and in other 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
## Remove cmd-space shortcut from Spotlight so we can use it for Alfred
#/usr/libexec/PlistBuddy ~/Library/Preferences/com.apple.symbolichotkeys.plist -c "Set AppleSymbolicHotKeys:64:enabled false"
# turn off the finder search shortcut also
#/usr/libexec/PlistBuddy ~/Library/Preferences/com.apple.symbolichotkeys.plist -c "Set AppleSymbolicHotKeys:65:enabled false"
# credit for these scripts: https://gist.github.com/kaloprominat/6111584
# start rectangle on login (find a way to do this, it doesn't work)
#osascript -e 'tell application "System Events" to make login item at end with properties {path:"/Applications/Spectacle.app", hidden:false}'
# delete login item
#osascript -e 'tell application "System Events" to delete login item "itemname"'
# list loginitems
#osascript -e 'tell application "System Events" to get the name of every login item'
# start Bartender at login also
# I can't figure out how Bartender sets this up. It's not adding it to the System Events login items
# and it's not adding it to loginwindow's defaults, either.
# this does not work:
# defaults write loginwindow AutoLaunchedApplicationDictionary -array-add '{ "Name" = "Notes" ; "Path" = "/Applications/Bartender\ 5.app"; "Hide" = 0; }'
# but this does, although it does not trigger the "launch at login" checkbox in Bartender's preferences
#osascript -e 'tell application "System Events" to make login item at end with properties {path:"/Applications/Bartender\\ 5.app", hidden:false}'
###############################################################################
# Misc / System #
###############################################################################
# Disable the crash reporter
#defaults write com.apple.CrashReporter DialogType -string "none"
# Reveal IP address, hostname, OS version, etc. when clicking the clock
# in the login window
sudo defaults write /Library/Preferences/com.apple.loginwindow AdminHostInfo HostName
# Restart automatically if the computer freezes
# sudo systemsetup -setrestartfreeze on
# Never go into computer sleep mode
#sudo systemsetup -setcomputersleep Off > /dev/null
# Disable Notification Center and remove the menu bar icon
# launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist 2> /dev/null
###############################################################################
# Safari & WebKit #
###############################################################################
# Set Safari’s home page to `about:blank` for faster loading
defaults write com.apple.Safari HomePage -string "about:blank"
# Prevent Safari from opening ‘safe’ files automatically after downloading
defaults write com.apple.Safari AutoOpenSafeDownloads -bool false
# Hide Safari’s bookmarks bar by default
defaults write com.apple.Safari ShowFavoritesBar -bool false
# Enable Safari’s debug menu
#defaults write com.apple.Safari IncludeInternalDebugMenu -bool true
# Enable the Develop menu and the Web Inspector in Safari
defaults write com.apple.Safari IncludeDevelopMenu -bool true
defaults write com.apple.Safari WebKitDeveloperExtrasEnabledPreferenceKey -bool true
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled -bool true
###############################################################################
# Time Machine #
###############################################################################
# Prevent Time Machine from prompting to use new hard drives as backup volume
defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true
##################
### Text Editing / Keyboards
##################
# Disable smart quotes and smart dashes
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
# Disable auto-correct
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
# 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
###############################################################################
# Screenshots / Screen #
###############################################################################
# Require password immediately after sleep or screen saver begins"
defaults write com.apple.screensaver askForPassword -int 1
defaults write com.apple.screensaver askForPasswordDelay -int 0
###############################################################################
# Trackpad, mouse, keyboard, Bluetooth accessories, and input #
###############################################################################
# Disable “natural” (Lion-style) scrolling
# Uncomment if you don't use scroll reverser
defaults write NSGlobalDomain com.apple.swipescrolldirection -bool false
# Stop iTunes from responding to the keyboard media keys
launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist 2> /dev/null
# Enable full keyboard access for all controls
# (e.g. enable Tab in modal dialogs)
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
# Set key repeat rate to fast
defaults write NSGlobalDomain KeyRepeat -int 2
# Reduce delay to repeat
defaults write NSGlobalDomain InitialKeyRepeat -int 15
# Increase trackpad speed
defaults write NSGlobalDomain com.apple.trackpad.scaling -int 2
# Turn off trackpad click noise
defaults write com.apple.AppleMultitouchTrackpad ActuationStrength -int 1
# Disabling press-and-hold for special keys in favor of key repeat
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false
# Turn off keyboard illumination when computer is not used for 5 minutes
defaults write com.apple.BezelServices kDimTime -int 300
###############################################################################
# Mac App Store #
###############################################################################
# Enable the automatic update check
defaults write com.apple.SoftwareUpdate AutomaticCheckEnabled -bool true
# Download newly available updates in background
defaults write com.apple.SoftwareUpdate AutomaticDownload -int 1
# Install System data files & security updates
defaults write com.apple.SoftwareUpdate CriticalUpdateInstall -int 1
###############################################################################
# Photos #
###############################################################################
# Prevent Photos from opening automatically when devices are plugged in
defaults -currentHost write com.apple.ImageCapture disableHotPlug -bool true
###############################################################################
# Google Chrome #
###############################################################################
# Disable the all too sensitive backswipe on trackpads
defaults write com.google.Chrome AppleEnableSwipeNavigateWithScrolls -bool false
##################################################################################
#### iTerm 2 #
##################################################################################
#### this is a bit of a messy process to ensure that iTerm will use the left option key as the meta key
#### but it is the only way I found to do it with consistently reproducible results
#### if you don't do the syncs, defaults read calls and waiting, then it does not always honor the settings
#### this was a pain in the ass to figure out - GR
###echo "Attempting to setup defaults for iTerm now. The app will open while this process runs."
###echo "Please do not touch the keyboard or mouse until this process completes."
###sleep 1
#### the defaults file is empty right now
#### create initial defaults for iterm so it will not ask when we quit it with this script
###defaults write com.googlecode.iterm2 PromptOnQuit -bool false
#### and turn on automatic checks so we're not bothered with that dialog either
###defaults write com.googlecode.iterm2 SUEnableAutomaticChecks -int 1
#### start iterm and exit it, so that it fills in the rest of the defaults
###open /Applications/iTerm.app &
#### wait for iTerm to start up...
###echo "Wait for iTerm to setup its default prefs"
###sleep 3
#### flush filesystem (not sure if this even does anything)
###sync
#### see what it wrote (in case a read causes anything cached to be flushed)
###numDefaults=`defaults read com.googlecode.iterm2 | wc -l`
####echo "num defaults read: $numDefaults"
#### kill it since the defaults plist should be filled in now
###killall iTerm2
#### wait for it to die
###pids=`ps uawwx | grep iTerm2 | grep -v grep | wc -l`
####echo "Pids: $pids"
###while [ $pids -gt 0 ]
###do
### #echo "still running..."
### sleep 1
### pids=`ps uawwx | grep iTerm2 | grep -v grep | wc -l`
###done
#### force FS flush
###sync
#### now we can alter prefs via PlistBuddy
###ITERM=$HOME/Library/Preferences/com.googlecode.iterm2.plist
#### set the left option key to Esc+ (so it will work as meta key properly)
#### for some reason the defaults plist is not written immediately,
#### so we have to keep trying to update it with PlistBuddy
###echo -n "Attempting to set meta key for iTerm2"
###counter=0
###maxTries=20
###while [ $counter -lt $maxTries ]
###do
### echo -n "."
### sleep 1
### # credit: https://raw.githubusercontent.com/therockstorm/dotfiles/master/init.sh
### # and for some reason the stderr redirect here still doesn't always redirect the error output... awesome.
### /usr/libexec/PlistBuddy -c 'Set :"New Bookmarks":0:"Option Key Sends" 2' $ITERM 2>&1>/dev/null
### if [ $? -eq 0 ]
### then
### echo " done"
### break
### fi
### counter=`expr $counter + 1`
###done
#### There were still cases where it was in the defaults plist, but not honored by the app
#### so we do a few more things here to try and ensure that the defaults are actually honored
####
#### let's try a sync again just in case
###sync
#### and another read to see if we reset any cache
###numDefaults=`defaults read com.googlecode.iterm2 | wc -l`
####echo "num defaults read: $numDefaults"
#### NOW the setting should be saved properly
###
#### reset the close confirmation dialog, since I do want it to ask
###defaults write com.googlecode.iterm2 PromptOnQuit -bool true
###############################################################################
# Terminal #
###############################################################################
# Enable option as meta key
# use the same trick that we did for iTerm...
echo "Attempting to setup defaults for Terminal now. The app will open while this process runs."
echo "Please do not touch the keyboard or mouse until this process completes."
sleep 1
# the defaults file is empty right now
# start Terminal and exit it, so that it fills in the rest of the defaults
open /Applications/Utilities/Terminal.app &
# wait for Terminal to start up...
echo "Wait for Terminal to setup its default prefs"
sleep 3
# flush filesystem (not sure if this even does anything)
sync
# see what it wrote (in case a read causes anything cached to be flushed)
numDefaults=`defaults read com.apple.Terminal | wc -l`
#echo "num defaults read: $numDefaults"
# kill it since the defaults plist should be filled in now
killall Terminal
# wait for it to die
pids=`ps uawwx | grep Terminal | grep -v grep | wc -l`
#echo "Pids: $pids"
while [ $pids -gt 0 ]
do
#echo "still running..."
sleep 1
pids=`ps uawwx | grep Terminal | grep -v grep | wc -l`
done
# force FS flush
sync
# now we can alter prefs via PlistBuddy
# set the left option key to Esc+ (so it will work as meta key properly)
# for some reason the defaults plist is not written immediately,
# so we have to keep trying to update it with PlistBuddy
echo -n "Attempting to set meta key for Terminal"
counter=0
maxTries=20
while [ $counter -lt $maxTries ]
do
echo -n "."
sleep 1
plutil -replace "Window Settings.Basic.useOptionAsMetaKey" -integer 1 ~/Library/Preferences/com.apple.Terminal.plist
if [ $? -eq 0 ]
then
echo " done"
break
fi
counter=`expr $counter + 1`
done
# There were still cases where it was in the defaults plist, but not honored by the app
# so we do a few more things here to try and ensure that the defaults are actually honored
#
# let's try a sync again just in case
sync
# and another read to see if we reset any cache
numDefaults=`defaults read com.apple.Terminal | wc -l`
#echo "num defaults read: $numDefaults"
# NOW the setting should be saved properly
# TODO would be nice to have the font size increase and window size as well
###############################################################################
# Energy settings #
###############################################################################
####### better battery life while sleeping
####
#### pmset -a = all power modes , -b = battery , -c = charger / wall power
####
#### More info:
#### https://www.lifewire.com/change-mac-sleep-settings-2260804
#### https://www.dssw.co.uk/reference/pmset.html
####
#### hibernatemode 3 = writes memory to disk, but keeps ram powered , 25 = writes to disk and does not power memory (takes longer to wake)
####
#### default for portables is "hibernatemode 3"
####sudo pmset -a hibernatemode 25 standby 0 autopoweroff 0
#### although, this makes it take much longer to wake from sleep, and sometimes it logs out entirely
#### benefits are not apparent
###
#### so stick with mode 3
###sudo pmset -a hibernatemode 3
###
#### tell mac to hibernate after a set time interval
###sudo pmset -a standby 1
#### battery % considered "high" (default)
####sudo pmset -a highstandbythreshold 50
#### num seconds to delay before hibernating when mac is put to sleep and battery has more than 'highstandbythreshold' % battery
###sudo pmset -a standbydelayhigh 600 # wait 10 minutes and then hibernate
#### num seconds to delay before hibernating when battery is < 50%
###sudo pmset -a standbydelaylow 120 # wait 2 minutes on low power
###
#### do not automatically hibernate
###sudo pmset -a autopoweroff 0
###
#### do not wake on "magic packet" over ethernet
###sudo pmset -a womp 0
###
#### do not wake when power source changes
###sudo pmset -a acwake 0
###
#### no sharing network services when sleeping
###sudo pmset -a networkoversleep 0
###
#### turn off Power Nap
#### more info here: https://www.howtogeek.com/277742/what-is-power-nap-in-macos/
###sudo pmset -a powernap 0
###
#### turn display off after 10 minutes on battery
###sudo pmset -b displaysleep 10
###
#### go to sleep after 20 minutes on battery
###sudo pmset -b sleep 20
###
#### turn off option that wakes mac when devices with same apple id are near
#### https://www.reddit.com/r/hackintosh/comments/9jfa8w/mojave_new_pmset_options/
###sudo pmset -a proximitywake 0
###
#### go to sleep after an hour when plugged in
###sudo systemsetup -setsleep 60
###
#### put display to sleep after 10 minutes when plugged in
###sudo systemsetup -setdisplaysleep 10
###
#### Turn off feature to preserve battery life while sleeping
#### https://discussions.apple.com/thread/8368663
###sudo pmset -b tcpkeepalive 0
###
#### Edit Mac-specific config to turn off tcpkeepalive and do-not-disturb while sleeping
#### keeps enhanced notifications from waking mac while sleeping, draining battery
#### Related:
#### https://forums.macrumors.com/threads/psa-if-your-2015-or-2016-mbp-has-some-battery-drain-while-sleeping-here-is-the-fix.2026702/
#### https://apple.stackexchange.com/questions/253776/macbook-pro-13-with-retina-display-consumes-10-battery-overnight-with-the-lid-c
#### https://support.apple.com/en-us/HT201960
###csrutil status | grep enabled > /dev/null
###if [ $? -eq 0 ]
###then
### echo "Cannot disable tcpkeepalive properly"
### echo "Please reboot and hold command-r to start the recovery tool"
### echo "When it loads, open the terminal and type `csrutil disable` and then reboot and try again"
### echo "When finished, reboot into the recovery tool, and enter 'csrutil enable' in the terminal again"
###else
### MODEL=`ioreg -l | awk '/board-id/{print $4}' | sed 's/[<">]//g'`
### echo "Altering configuration for model $MODEL"
### echo "Disable network wake when sleeping"
### sudo /usr/libexec/PlistBuddy -c "Set :IOPlatformPowerProfile:TCPKeepAliveDuringSleep false" /System/Library/Extensions/IOPlatformPluginFamily.kext/Contents/PlugIns/X86PlatformPlugin.kext/Contents/Resources/$MODEL.plist
### echo "Enable Do Not Disturb while display is asleep"
### sudo /usr/libexec/PlistBuddy -c "Set :IOPlatformPowerProfile:DNDWhileDisplaySleeps true" /System/Library/Extensions/IOPlatformPluginFamily.kext/Contents/PlugIns/X86PlatformPlugin.kext/Contents/Resources/$MODEL.plist
###fi
#############################################
### Install dotfiles repo
#############################################
# dotfiles for vs code, emacs, gitconfig, oh my zsh, etc.
# git clone [email protected]:gricard/dotfiles.git
# cd dotfiles
echo ""
echo "Done!" $cyan
echo
echo
echo "Additional manual setup (for now):"
echo " - adjust the screen resolution manually (for now)"
echo " - install the Sync Settings VS Code extension and connect to your gist!"
echo " - Install JetBrains IDEs via Toolbox"
echo " - Install React Dev Tools in Chrome, Firefox, etc."
echo " - System Prefs -> Bluetooth -> Advanced -> Allow Bluetooth devices to wake this computer"
echo " - System Prefs -> Notifications -> Turn on Do Not Disturb... -> When the display is sleeping"
echo " - System Prefs -> Security -> Require password immediately after sleep"
echo
echo ""
echo ""
cecho "################################################################################" $white
echo ""
echo ""
cecho "Note that some of these changes require a logout/restart to take effect." $red
echo ""
echo ""
echo -n "Check for and install available OSX updates, install, and automatically restart? (y/n)? "
read response
if [ "$response" != "${response#[Yy]}" ] ;then
softwareupdate -i -a --restart
fi