-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacosx_tweaks
executable file
·462 lines (365 loc) · 14.7 KB
/
macosx_tweaks
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
#! /bin/bash
# Automate change various Mac OS X settings.
# It can be run any number of times and it will tell you what it changes,
# in case settings get reverted.
# recent ideas from:
# https://raw.githubusercontent.com/mathiasbynens/dotfiles/master/.macos
set -eu
# 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
function errordie {
echo "Error: $*" 1>&2
exit 1
}
restart_finder=
restart_systemuiserver=
# Like "defaults write ..." but prints first arg to STDOUT if a
# change is made, nothing otherwise.
function d {
local description="$1"; shift
local domain="$1"; shift
local key="$1"; shift
local current
local old
local value
local changed
# $* is the value, which can be a single value or a pair:
# -string string_value
# -bool[ean] (true | false | yes | no)
# -int[eger] <integer_value>
# we punt on all others
if current=$(defaults read "$domain" "$key" 2>/dev/null); then
# value for key exists, see if it's the same as what we want
# it to be
if [ $# -eq 1 ]; then
# simple case of a single value
if [ "$current" = "$1" ]; then
: # Nothing to do
else
old=$current
echo $description
defaults write "$domain" "$key" "$@"
echo " ****** old value was: $old"
changed=yes
fi
else
case "$1" in
-bool|-boolean)
case $2 in
true|yes) value=1 ;;
false|no) value=0 ;;
*) errordie bad -boolean value: $2 ;;
esac
;;
-string) value="$2" ;;
-int|-integer) value="$2" ;;
*) errordie $1 is unrecognized value ;;
esac
if [ "$current" = "$value" ]; then
: # Nothing to do
else
old=$current
echo $description
defaults write "$domain" "$key" "$@"
echo " ****** old value was: $old"
changed=yes
fi
fi
else
# didn't exist, write it
echo $description
defaults write "$domain" "$key" "$@"
echo " NEW SETTING"
changed=yes
fi
if [ "$domain" = "com.apple.finder" ] && [ "$changed" ]; then
restart_finder=xxx
fi
if [ "$domain" = "com.apple.menuextra.clock" ] && [ "$changed" ]; then
restart_systemuiserver=xxx
fi
}
d "Suppress Apple Photos from start on hotplug of cameras" \
com.apple.ImageCapture disableHotPlug -bool true
d "Suppress xterm when X11 starts" org.x.X11 app_to_run $(which true)
d "Always show tab bar in Terminal" com.Apple.Terminal ShowTabBar 1
d "Setting screenshot location to $HOME/Downloads" \
com.apple.screencapture location -string "$HOME/Downloads"
d "Disable floating thumbnail" \
com.apple.screencapture show-thumbnail -bool false
d "Setting screenshot format to PNG" \
com.apple.screencapture type -string "png"
d "Disable shadow in screenshots" \
com.apple.screencapture disable-shadow -bool true
d "Enable subpixel font rendering on non-Apple LCDs" \
NSGlobalDomain AppleFontSmoothing -int 2
# CMD-CTRL click to drag window on any part of it
# (can't use d because it doesn't have enough args)
# requires logout/login
defaults write -g NSWindowShouldDragOnGesture -bool true
d "Automatically quit printer app once the print jobs complete" \
com.apple.print.PrintingPrefs "Quit When Finished" -bool true
d "Ask for password when wake from sleep/screensaver" \
com.apple.screensaver askForPassword -int 1
d "Password delay to 6 seconds" \
com.apple.screensaver askForPasswordDelay -int 60
d "Set menubar date format" \
com.apple.menuextra.clock DateFormat "MMM d h:mm a"
[ "$USER" = "layer" ] &&
d "Disable \"Are you sure you want to open this application?\" dialog" \
com.apple.LaunchServices LSQuarantine -bool false
############## Finder...
d "Use list view in all Finder windows" \
com.apple.finder FXPreferredViewStyle Nlsv
d "Do NOT show icons for hard drives, servers, etc on the desktop" \
com.apple.finder ShowExternalHardDrivesOnDesktop -bool false
d "Show status bar in Finder" com.apple.finder ShowStatusBar -bool true
d "Show path bar in Finder" com.apple.finder ShowPathbar -bool true
d "Display full POSIX path as Finder window title" \
com.apple.finder _FXShowPosixPathInTitle -bool true
d "Keep folders with files when sorting by name" \
com.apple.finder _FXSortFoldersFirst -bool false
d "Search the current folder by default" \
com.apple.finder FXDefaultSearchScope -string "SCcf"
d "Disable the warning when changing a file extension" \
com.apple.finder FXEnableExtensionChangeWarning -bool false
d "Disable window animations and Get Info animations" \
com.apple.finder DisableAllAnimations -bool true
# For other paths, use `PfLo` and `file:///full/path/here/`
#defaults write com.apple.finder NewWindowTarget -string "PfLo"
# Set Applications as the default location for new Finder windows
d "New Finder windows start in /Applications" \
com.apple.finder NewWindowTargetPath -string "file:///Applications/"
d "Do not show recent tags" com.apple.finder ShowRecentTags -bool false
# Too annoying
d "Do NOT show hidden files" com.apple.finder AppleShowAllFiles -bool false
d "Show all filename extensions in Finder" \
NSGlobalDomain AppleShowAllExtensions -bool true
# Enable spring loading for directories
#defaults write NSGlobalDomain com.apple.springing.enabled -bool true
# Remove the spring loading delay for directories
#defaults write NSGlobalDomain com.apple.springing.delay -float 0
d "Avoid the creation of .DS_Store files on network volumes" \
com.apple.desktopservices DSDontWriteNetworkStores -bool true
d "Avoid the creation of .DS_Store files on USB drives" \
com.apple.desktopservices DSDontWriteUSBStores -bool true
d "Disable the warning before emptying the Trash" \
com.apple.finder WarnOnEmptyTrash -bool false
# Show the ~/Library and /Volumes
[ "$USER" = "layer" ] &&
chflags nohidden ~/Library
[ "$USER" = "layer" ] &&
sudo chflags nohidden /Volumes
############## ...Finder
# Hot corners
# Possible values:
# 0: no-op
# 2: Mission Control
# 3: Show application windows
# 4: Desktop
# 5: Start screen saver
# 6: Disable screen saver
# 7: Dashboard
# 10: Put display to sleep
# 11: Launchpad
# 12: Notification Center
# Bottom left screen corner → Start screen saver
d "Hot corner bottom left, part1" com.apple.dock wvous-bl-corner -int 10
d "Hot corner bottom left, part2" com.apple.dock wvous-bl-modifier -int 0
d "Show the main window when launching Activity Monitor" \
com.apple.ActivityMonitor OpenMainWindow -bool true
d "Visualize CPU usage in the Activity Monitor Dock icon" \
com.apple.ActivityMonitor IconType -int 5
d "Show all processes in Activity Monitor" \
com.apple.ActivityMonitor ShowCategory -int 0
d "Sort Activity Monitor results by CPU usage" \
com.apple.ActivityMonitor SortColumn -string "CPUUsage"
d "Sort Activity Monitor direction" \
com.apple.ActivityMonitor SortDirection -int 0
d "Minimize windows into their app icon" \
com.apple.dock minimize-to-application -bool true
d "Show indicator lights for open applications in the Dock" \
com.apple.dock show-process-indicators -bool true
d "No animation opening applications from the Dock" \
com.apple.dock launchanim -bool false
d "Lower-left hot corner: sleep display" \
com.apple.dock wvous-bl-corner -int 10
d "Lower-left hot corner: sleep display, part 2" \
com.apple.dock wvous-bl-modifier -int 0
d "Prevent TM from prompting to use new drives as backup volumes" \
com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true
# Assuming this won't hurt on non-laptops
d "Turn off keyboard illumination when not used for 5 minutes" \
com.apple.BezelServices kDimTime -int 300
d "InitialKeyRepeat" NSGlobalDomain InitialKeyRepeat -int 35
d "KeyRepeat" NSGlobalDomain KeyRepeat -int 2
d "Terminal: copy attributes from Basic profile" \
com.apple.Terminal CopyAttributesProfile Basic
# See: https://security.stackexchange.com/a/47786/8918
d "Enable Secure Keyboard Entry in Terminal.app" \
com.apple.terminal SecureKeyboardEntry -bool true
d "Disable iCloud save default" \
NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false
d "Disable smart quotes" \
NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
d "Disable smart dashes" \
NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
d "Disable App Nap" \
NSGlobalDomain NSAppSleepDisabled -bool true
d "Enable the debug menu in Disk Utility" \
com.apple.DiskUtility DUDebugMenuEnabled -bool true
d "Enable the advanced image options in Disk Utility" \
com.apple.DiskUtility advanced-image-options -bool true
d "Enable Debug Menu in the Mac App Store" \
com.apple.appstore ShowDebugMenu -bool true
d "Chrome: Use the system-native print preview dialog" \
com.google.Chrome DisablePrintPreview -bool true
# Remove the badge associated with "start using icloud" in the
# System Preferences. Man, that was annoying!!
#defaults delete com.apple.systempreferences AttentionPrefBundleIDs || true
[ "$restart_finder" ] && killall Finder
[ "$restart_systemuiserver" ] &&
echo "starting system UI server" &&
killall -KILL SystemUIServer
###############################################################################
# This should be the default on Mac OS X. It prevents all processes
# from getting sudo privs.
if ! sudo grep tty_tickets /etc/sudoers > /dev/null; then
cat<<EOF
TODO: add "Defaults tty_tickets" to /etc/sudoers
EOF
fi
if ! sudo grep -E '^Defaults.*HOME MAIL' /etc/sudoers > /dev/null; then
cat<<EOF
TODO: add this to /etc/sudoers:
Defaults env_keep += "HOME MAIL"
EOF
fi
shell="$(dscl . -read /Users/$USER UserShell)"
if [[ ! "$shell" =~ UserShell:\ (.*/bash) ]]; then
shell=${BASH_REMATCH[1]}
case $temp in
/usr/local/bin/bash) ;;
/opt/homebrew/bin/bash) ;;
/opt/local/bin/bash) ;;
*) cat <<EOF
Unknown shell: $shell
Change it in System Preferences, Users & Groups, right-click on user and
select "Advanced Options..."
EOF
esac
fi
# Disable captive portal window
# https://web.archive.org/web/20130407200745/http://www.divertednetworks.net/apple-captiveportal.html
capnetsupsettings=/Library/Preferences/SystemConfiguration/CaptiveNetworkSupport/Settings.plist
if [ -f "capnetsupsettings" ] && grep -q -F apple.com $capnetsupsettings; then
echo Fixing $capnetsupsettings...
sudo gsed -i.orig 's/\.apple\.com/\.localhost/g' $capnetsupsettings
fi
# Restart automatically if the computer freezes
sudo systemsetup -setrestartfreeze on
# Never go into computer sleep mode
[ "$USER" = "layer" ] &&
sudo systemsetup -setcomputersleep Off > /dev/null
# clear the Quicklook thumbnail cache
qlmanage -r cache
tempfile="/tmp/tweakstemp$$"
rm -f $tempfile
function exit_cleanup {
/bin/rm -f $tempfile
}
trap exit_cleanup EXIT
# prevent auto-mounting of remote file systems in Finder by directing
# these extensions to Safari
if type -p duti > /dev/null; then
duti -s com.apple.Safari afp
duti -s com.apple.Safari ftp
duti -s com.apple.Safari nfs
duti -s com.apple.Safari smb
duti -s com.apple.TextEdit public.unix-executable
fi
exit 0
###############################################################################
## rest deemed too dangerous for new Mac Pro
if [ -e /Private/var/vm/sleepimage ]; then
echo "Remove the sleep image file to save disk space"
sudo rm -f /Private/var/vm/sleepimage
echo "Creating a zero-byte file instead..."
sudo touch /Private/var/vm/sleepimage
echo "...and make sure it cannot be rewritten"
sudo chflags uchg /Private/var/vm/sleepimage
fi
function xpmset {
local description="$1"; shift
local flag="$1"; shift
local setting="$1"; shift
local value="$1"
local current=$(pmset -g | grep " $setting " | awk '{print $2}')
if [ "$current" != "$value" ]; then
echo $description
echo sudo pmset $flag "$setting" "$value"
fi
}
# speeds up entering sleep mode
xpmset "Disable hibernation" -a hibernatemode 0
model=`ioreg -l |fgrep '"product-name" = <' |cut -d ""="" -f 2|sed -e 's/[^[:alnum:]]//g' | sed 's/[0-9]//g'`
if [ "$model" == "MacBookPro" ]; then
# so I can wake
xpmset "DO wake on magic packet" -a womp 1
# better have an SSD!!!!
xpmset "Disable the sudden motion sensor" -a sms 0
# http://www.cultofmac.com/221392/quick-hack-speeds-up-retina-macbooks-wake-from-sleep-os-x-tips/
xpmset "Speedup wake from sleep" -a standbydelay 86400
elif [ "$model" == "MacPro" ]; then
xpmset "Disable computer sleep" -a sleep 0
xpmset "Set display sleep to 10 minutes" -a displaysleep 10
xpmset "Set disk sleep to 10 minutes" -a disksleep 10
xpmset "Set autorestart to off" -a autorestart 0
xpmset "DO NOT wake on magic packet" -a womp 0
fi
function ethernet_device_name {
networksetup -listallnetworkservices | grep Ethernet | head -1
}
ethernet="$(ethernet_device_name)"
# This makes wake from sleep work better:
sudo networksetup -setv6LinkLocal "$ethernet"
./check_fulldiskaccess.sh
# this is SOOOOOO annoying. Even if you have it turned off in
# prefs, it still runs.
# from https://superuser.com/a/1649000
### to find it do this:
# launchctl list | grep microsoft
# sudo launchctl list | grep microsoft
# whichever it's running as ($USER or root), do this:
# launchctl unload /Library/LaunchAgents/com.microsoft.update.agent.plist
muaplist=/Library/LaunchAgents/com.microsoft.update.agent.plist
if [ -f "$muaplist" ]; then
#### it runs as `$USER`
# sudo launchctl disable "gui/$(id -u)/com.microsoft.update.agent"
#### let's see if this is good enough to stop the MFer
# launchctl disable "gui/$(id -u)/com.microsoft.update.agent"
#### this causes it to not run manually
#launchctl unload "$muaplist"
# check once a week, if the above doesn't work
sudo plutil -replace StartInterval -integer $(( 7 * 3600 * 24 )) "$muaplist"
#### check status:
#plutil -p "$muaplist"
fi
if [ -f /Library/LaunchAgents/com.microsoft.OneDriveStandaloneUpdater.plist ]; then
launchctl unload /Library/LaunchAgents/com.microsoft.OneDriveStandaloneUpdater.plist
exit 0
###############################################################################
##### TODO ####################################################################
###############################################################################
# need to write xnvram function to mirror above ones
xnvram "Disable sound on boot" SystemAudioVolume=" "
# Disable Notification Center and remove the menu bar icon
launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist 2> /dev/null
# Cannot automate this, since it gets turned back on under various
# conditions. Also, can query the current value.
# Perhaps run as a root cron job??
echo "Disabling TM local snapshots"
hash tmutil &> /dev/null && sudo tmutil disablelocal