Repository navigation
Expand file tree
/
Copy pathmacos
More file actions
executable file
·1480 lines (1323 loc) · 46.1 KB
/
Copy pathmacos
File metadata and controls
executable file
·1480 lines (1323 loc) · 46.1 KB
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
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
set -euo pipefail
DRY_RUN=false
CHOICE=1
SAVE_FILE=''
CONFIG_FILE=''
COMMANDS=()
DESCRIPTIONS=()
SETTINGS=()
RESTART_DOCK=false
RESTART_FINDER=false
RESTART_SYSTEMUISERVER=false
if [ -t 1 ] && [ "${NO_COLOR:-}" = "" ]; then
BOLD=$(printf '\033[1m')
DIM=$(printf '\033[2m')
RED=$(printf '\033[31m')
GREEN=$(printf '\033[32m')
YELLOW=$(printf '\033[33m')
BLUE=$(printf '\033[34m')
RESET=$(printf '\033[0m')
else
BOLD=''
DIM=''
RED=''
GREEN=''
YELLOW=''
BLUE=''
RESET=''
fi
usage() {
cat <<EOF
Usage: ./macos [--dry-run] [--save FILE] [--config FILE]
Options:
-n, --dry-run Choose tweaks and print commands without applying them.
-s, --save Save selected tweaks to a local config file.
-c, --config Load selected tweaks from a local config file.
-h, --help Show this help.
EOF
}
info() {
printf '%s\n' "${BLUE}${BOLD}$1${RESET}"
}
note() {
printf '%s\n' "${DIM}$1${RESET}"
}
warn() {
printf '%s\n' "${YELLOW}$1${RESET}"
}
fail() {
printf '%s\n' "${RED}${BOLD}Error:${RESET} $1" >&2
exit 1
}
parse_args() {
while [ "$#" -gt 0 ]; do
case "$1" in
-n|--dry-run)
DRY_RUN=true
;;
-s|--save)
[ "$#" -gt 1 ] || fail '--save requires a file path.'
SAVE_FILE=$2
shift
;;
-c|--config)
[ "$#" -gt 1 ] || fail '--config requires a file path.'
CONFIG_FILE=$2
shift
;;
-h|--help)
usage
exit 0
;;
*)
usage >&2
exit 2
;;
esac
shift
done
}
read_default() {
local domain=$1 key=$2
defaults read "$domain" "$key" 2>/dev/null || printf 'not set'
}
read_current_host_default() {
local domain=$1 key=$2
defaults -currentHost read "$domain" "$key" 2>/dev/null || printf 'not set'
}
read_system_timezone() {
local output=
output=$(systemsetup -gettimezone 2>/dev/null || true)
case "$output" in
'Time Zone: '*)
printf '%s' "${output#Time Zone: }"
;;
*)
printf 'not set'
;;
esac
}
add_command() {
local setting=${3:-}
DESCRIPTIONS+=("$1")
COMMANDS+=("$2")
if [ -n "$setting" ]; then
SETTINGS+=("$setting")
fi
}
add_setting() {
local key=$1 value=$2 description=$3 command=$4
add_command "$description" "$command" "$key=$value"
}
save_config() {
local save_path=$1 save_dir command line
save_path=$(expand_user_path "$save_path")
save_dir=$(dirname "$save_path")
mkdir -p "$save_dir"
{
printf '%s\n' '# Generated by ./macos. Review before reusing on another machine.'
printf '%s\n' '# Format: scope:domain:key=type:value'
for command in "${COMMANDS[@]}"; do
while IFS= read -r line; do
[ -n "$line" ] && printf '%s\n' "$line"
done < <(command_to_config "$command")
done
} >"$save_path"
printf '%s\n' "${GREEN}[OK]${RESET} Saved selected tweaks to $save_path"
}
command_to_config() {
local command=$1 part
local parts=()
IFS=';' read -ra parts <<<"$command"
for part in "${parts[@]}"; do
part=${part#"${part%%[![:space:]]*}"}
part=${part%"${part##*[![:space:]]}"}
command_part_to_config "$part"
done
}
command_part_to_config() {
local part=$1 scope domain key type value values
[ -n "$part" ] || return 0
eval "set -- $part"
if [ "${1:-}" = "sudo" ] && [ "${2:-}" = "systemsetup" ] && [ "${3:-}" = "-settimezone" ]; then
printf '%s=%s\n' 'system:timezone' "${4:-}"
return 0
fi
if [ "${1:-}" = "defaults" ] && [ "${2:-}" = "delete" ]; then
printf 'defaults-delete:%s:%s=true\n' "$3" "$4"
return 0
fi
scope=defaults
if [ "${1:-}" = "defaults" ] && [ "${2:-}" = "-currentHost" ] && [ "${3:-}" = "write" ]; then
scope=currentHost
shift 3
elif [ "${1:-}" = "defaults" ] && [ "${2:-}" = "write" ]; then
shift 2
else
return 0
fi
domain=${1:-}
key=${2:-}
type=${3:-}
shift 3 || true
case "$domain" in
*/com.apple.universalaccess.plist)
domain=com.apple.universalaccess
;;
esac
case "$type" in
-bool|-boolean)
printf '%s:%s:%s=bool:%s\n' "$scope" "$domain" "$key" "$1"
;;
-int)
printf '%s:%s:%s=int:%s\n' "$scope" "$domain" "$key" "$1"
;;
-float)
printf '%s:%s:%s=float:%s\n' "$scope" "$domain" "$key" "$1"
;;
-string)
printf '%s:%s:%s=string:%s\n' "$scope" "$domain" "$key" "$1"
;;
-array)
values=$(printf '%s|' "$@")
values=${values%|}
printf '%s:%s:%s=array:%s\n' "$scope" "$domain" "$key" "$values"
;;
esac
}
load_config_file() {
local config_path=$1 line key value
config_path=$(expand_user_path "$config_path")
[ -f "$config_path" ] || fail "Config file not found: $config_path"
while IFS= read -r line || [ -n "$line" ]; do
case "$line" in
''|'#'*)
continue
;;
esac
key=${line%%=*}
value=${line#*=}
add_config_setting "$key" "$value"
done <"$config_path"
}
add_config_setting() {
local key=$1 value=$2 scope domain defaults_key type raw command description item
local quoted_value array_values
if [ "$key" = "system:timezone" ]; then
quoted_value=$(shell_quote "$value")
add_command "Set timezone to $value" "sudo systemsetup -settimezone $quoted_value >/dev/null"
return
fi
IFS=':' read -r scope domain defaults_key <<<"$key"
if [ "$scope" = "defaults-delete" ]; then
add_command "Delete $domain $defaults_key" "defaults delete $domain $defaults_key 2>/dev/null || true"
set_restart_for_domain "$domain"
return
fi
type=${value%%:*}
raw=${value#*:}
case "$type" in
bool)
command="defaults write $domain $defaults_key -bool $raw"
;;
int)
command="defaults write $domain $defaults_key -int $raw"
;;
float)
command="defaults write $domain $defaults_key -float $raw"
;;
string)
quoted_value=$(shell_quote "$raw")
command="defaults write $domain $defaults_key -string $quoted_value"
if [ "$domain" = "com.apple.screencapture" ] && [ "$defaults_key" = "location" ]; then
command="mkdir -p $quoted_value; $command"
fi
;;
array)
command="defaults write $domain $defaults_key -array"
IFS='|' read -ra array_values <<<"$raw"
for item in "${array_values[@]}"; do
quoted_value=$(shell_quote "$item")
command="$command $quoted_value"
done
;;
*)
warn "Skipping unknown config value: $key=$value"
return
;;
esac
if [ "$domain" = "com.apple.universalaccess" ]; then
command=${command/defaults write com.apple.universalaccess/defaults write \"\$HOME\/Library\/Preferences\/com.apple.universalaccess.plist\"}
fi
if [ "$scope" = "currentHost" ]; then
command=${command/defaults write/defaults -currentHost write}
elif [ "$scope" != "defaults" ]; then
warn "Skipping unknown config scope: $key"
return
fi
description="Set $domain $defaults_key to $raw"
if [ "$domain" = "com.apple.universalaccess" ]; then
case "$defaults_key" in
closeViewScrollWheelToggle)
if [ "$raw" = "true" ]; then
description='Enable scroll gesture zoom'
else
description='Disable scroll gesture zoom'
fi
;;
HIDScrollZoomModifierMask)
description="Set scroll gesture zoom modifier to $(modifier_label "$raw")"
;;
closeViewZoomFollowsFocus)
if [ "$raw" = "true" ]; then
description='Follow keyboard focus while zoomed in'
else
description='Do not follow keyboard focus while zoomed in'
fi
;;
esac
fi
add_command "$description" "$command" "$key=$value"
set_restart_for_domain "$domain"
}
set_restart_for_domain() {
case "$1" in
com.apple.dock)
RESTART_DOCK=true
;;
com.apple.finder)
RESTART_FINDER=true
;;
com.apple.screencapture)
RESTART_SYSTEMUISERVER=true
;;
esac
}
shell_quote() {
printf '%q' "$1"
}
expand_user_path() {
case "$1" in
'~')
printf '%s' "$HOME"
;;
'~/'*)
printf '%s/%s' "$HOME" "${1#\~/}"
;;
*)
printf '%s' "$1"
;;
esac
}
ask_choice() {
local prompt=$1 current=$2
shift 2
local options=("$@")
local choice=
printf '\n%s\n' "${BOLD}$prompt${RESET}"
printf '%s\n' "${DIM}Current: $current${RESET}"
local i=1
for option in "${options[@]}"; do
printf ' %s) %s\n' "$i" "$option"
i=$((i + 1))
done
while true; do
printf 'Selection [1]: '
read -r choice
choice=${choice:-1}
case "$choice" in
''|*[!0-9]*)
warn "Choose a number between 1 and ${#options[@]}."
;;
*)
if [ "$choice" -ge 1 ] && [ "$choice" -le "${#options[@]}" ]; then
CHOICE=$choice
return 0
fi
warn "Choose a number between 1 and ${#options[@]}."
;;
esac
done
}
confirm() {
local prompt=$1 answer=
while true; do
printf '%s [y/N]: ' "$prompt"
read -r answer
case "$answer" in
y|Y|yes|YES)
return 0
;;
''|n|N|no|NO)
return 1
;;
*)
warn 'Please answer y or n.'
;;
esac
done
}
configure_language_timezone() {
local timezone quoted_timezone languages locale
info 'Language and Timezone'
languages=$(read_default NSGlobalDomain AppleLanguages)
locale=$(read_default NSGlobalDomain AppleLocale)
ask_choice 'Language and locale' "languages: $languages, locale: $locale" \
'Keep current setting' \
'English US + Portuguese Brazil, en_US locale' \
'Custom primary language and locale'
case "$CHOICE" in
2)
add_command 'Set languages to English US and Portuguese Brazil' 'defaults write NSGlobalDomain AppleLanguages -array "en-US" "pt_BR"; defaults write NSGlobalDomain AppleLocale -string "en_US"'
;;
3)
local primary_language=
local custom_locale=
local quoted_language=
local quoted_locale=
printf 'Primary language, for example en-US: '
read -r primary_language
[ -n "$primary_language" ] || fail 'Primary language cannot be empty.'
printf 'Locale, for example en_US: '
read -r custom_locale
[ -n "$custom_locale" ] || fail 'Locale cannot be empty.'
quoted_language=$(shell_quote "$primary_language")
quoted_locale=$(shell_quote "$custom_locale")
add_command "Set language to $primary_language and locale to $custom_locale" "defaults write NSGlobalDomain AppleLanguages -array $quoted_language; defaults write NSGlobalDomain AppleLocale -string $quoted_locale"
;;
esac
ask_choice 'Timezone' "$(read_system_timezone)" \
'Keep current setting' \
'America/Sao_Paulo' \
'Custom timezone'
case "$CHOICE" in
2)
add_command 'Set timezone to America/Sao_Paulo' 'sudo systemsetup -settimezone "America/Sao_Paulo" >/dev/null'
;;
3)
printf 'Timezone, for example America/Sao_Paulo: '
read -r timezone
[ -n "$timezone" ] || fail 'Timezone cannot be empty.'
quoted_timezone=$(shell_quote "$timezone")
add_command "Set timezone to $timezone" "sudo systemsetup -settimezone $quoted_timezone >/dev/null"
;;
esac
}
configure_keyboard() {
info 'Keyboard'
ask_choice 'Key repeat speed' "$(read_default NSGlobalDomain KeyRepeat)" \
'Keep current setting' \
'macOS default' \
'Fast' \
'Very fast' \
'Custom value'
case "$CHOICE" in
2)
add_command 'Set key repeat speed to macOS default' 'defaults delete NSGlobalDomain KeyRepeat 2>/dev/null || true'
;;
3)
add_command 'Set key repeat speed to fast' 'defaults write NSGlobalDomain KeyRepeat -int 2'
;;
4)
add_command 'Set key repeat speed to very fast' 'defaults write NSGlobalDomain KeyRepeat -int 1'
;;
5)
local value=
printf 'Custom KeyRepeat value: '
read -r value
[[ "$value" =~ ^[0-9]+$ ]] || fail 'KeyRepeat must be a number.'
add_command "Set key repeat speed to $value" "defaults write NSGlobalDomain KeyRepeat -int $value"
;;
esac
ask_choice 'Initial key repeat delay' "$(read_default NSGlobalDomain InitialKeyRepeat)" \
'Keep current setting' \
'macOS default' \
'Short' \
'Very short' \
'Custom value'
case "$CHOICE" in
2)
add_command 'Set initial key repeat delay to macOS default' 'defaults delete NSGlobalDomain InitialKeyRepeat 2>/dev/null || true'
;;
3)
add_command 'Set initial key repeat delay to short' 'defaults write NSGlobalDomain InitialKeyRepeat -int 15'
;;
4)
add_command 'Set initial key repeat delay to very short' 'defaults write NSGlobalDomain InitialKeyRepeat -int 10'
;;
5)
local value=
printf 'Custom InitialKeyRepeat value: '
read -r value
[[ "$value" =~ ^[0-9]+$ ]] || fail 'InitialKeyRepeat must be a number.'
add_command "Set initial key repeat delay to $value" "defaults write NSGlobalDomain InitialKeyRepeat -int $value"
;;
esac
ask_choice 'Press and hold accent popup' "$(read_default NSGlobalDomain ApplePressAndHoldEnabled)" \
'Keep current setting' \
'Enable accents' \
'Disable accents for faster key repeat'
case "$CHOICE" in
2)
add_command 'Enable press-and-hold accents' 'defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool true'
;;
3)
add_command 'Disable press-and-hold accents' 'defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false'
;;
esac
ask_choice 'Use F1, F2, etc. as standard function keys' "$(read_default NSGlobalDomain com.apple.keyboard.fnState)" \
'Keep current setting' \
'Enable standard function keys' \
'Use media/special keys by default'
case "$CHOICE" in
2)
add_command 'Use F1, F2, etc. as standard function keys' 'defaults write -g com.apple.keyboard.fnState -bool true'
;;
3)
add_command 'Use media/special keys by default' 'defaults write -g com.apple.keyboard.fnState -bool false'
;;
esac
}
modifier_label() {
case "$1" in
0) printf 'No modifier' ;;
131072) printf 'Shift' ;;
262144) printf 'Control' ;;
524288) printf 'Option' ;;
1048576) printf 'Command' ;;
*) printf 'Custom value %s' "$1" ;;
esac
}
configure_accessibility() {
local zoom_enabled zoom_modifier
info 'Accessibility'
zoom_enabled=$(read_default com.apple.universalaccess closeViewScrollWheelToggle)
zoom_modifier=$(read_default com.apple.universalaccess HIDScrollZoomModifierMask)
ask_choice 'Use scroll gesture with modifier key to zoom' "enabled: $zoom_enabled, modifier: $(modifier_label "$zoom_modifier") ($zoom_modifier)" \
'Keep current setting' \
'Enable with Control' \
'Enable with Option' \
'Enable with Command' \
'Enable with Shift' \
'Disable'
case "$CHOICE" in
2)
add_command 'Enable scroll gesture zoom with Control' 'defaults write "$HOME/Library/Preferences/com.apple.universalaccess.plist" closeViewScrollWheelToggle -bool true; defaults write "$HOME/Library/Preferences/com.apple.universalaccess.plist" HIDScrollZoomModifierMask -int 262144'
;;
3)
add_command 'Enable scroll gesture zoom with Option' 'defaults write "$HOME/Library/Preferences/com.apple.universalaccess.plist" closeViewScrollWheelToggle -bool true; defaults write "$HOME/Library/Preferences/com.apple.universalaccess.plist" HIDScrollZoomModifierMask -int 524288'
;;
4)
add_command 'Enable scroll gesture zoom with Command' 'defaults write "$HOME/Library/Preferences/com.apple.universalaccess.plist" closeViewScrollWheelToggle -bool true; defaults write "$HOME/Library/Preferences/com.apple.universalaccess.plist" HIDScrollZoomModifierMask -int 1048576'
;;
5)
add_command 'Enable scroll gesture zoom with Shift' 'defaults write "$HOME/Library/Preferences/com.apple.universalaccess.plist" closeViewScrollWheelToggle -bool true; defaults write "$HOME/Library/Preferences/com.apple.universalaccess.plist" HIDScrollZoomModifierMask -int 131072'
;;
6)
add_command 'Disable scroll gesture zoom' 'defaults write "$HOME/Library/Preferences/com.apple.universalaccess.plist" closeViewScrollWheelToggle -bool false'
;;
esac
ask_choice 'Follow keyboard focus while zoomed in' "$(read_default com.apple.universalaccess closeViewZoomFollowsFocus)" \
'Keep current setting' \
'Follow keyboard focus while zoomed' \
'Do not follow keyboard focus while zoomed'
case "$CHOICE" in
2)
add_command 'Follow keyboard focus while zoomed in' 'defaults write "$HOME/Library/Preferences/com.apple.universalaccess.plist" closeViewZoomFollowsFocus -bool true'
;;
3)
add_command 'Do not follow keyboard focus while zoomed in' 'defaults write "$HOME/Library/Preferences/com.apple.universalaccess.plist" closeViewZoomFollowsFocus -bool false'
;;
esac
}
configure_finder() {
info 'Finder'
ask_choice 'Finder status bar' "$(read_default com.apple.finder ShowStatusBar)" \
'Keep current setting' \
'Show status bar' \
'Hide status bar'
case "$CHOICE" in
2)
add_command 'Show Finder status bar' 'defaults write com.apple.finder ShowStatusBar -bool true'
RESTART_FINDER=true
;;
3)
add_command 'Hide Finder status bar' 'defaults write com.apple.finder ShowStatusBar -bool false'
RESTART_FINDER=true
;;
esac
ask_choice 'Show hidden files' "$(read_default com.apple.finder AppleShowAllFiles)" \
'Keep current setting' \
'Show hidden files' \
'Hide hidden files'
case "$CHOICE" in
2)
add_command 'Show hidden files in Finder' 'defaults write com.apple.finder AppleShowAllFiles -bool true'
RESTART_FINDER=true
;;
3)
add_command 'Hide hidden files in Finder' 'defaults write com.apple.finder AppleShowAllFiles -bool false'
RESTART_FINDER=true
;;
esac
ask_choice 'Show filename extensions' "$(read_default NSGlobalDomain AppleShowAllExtensions)" \
'Keep current setting' \
'Show all extensions' \
'Hide extensions'
case "$CHOICE" in
2)
add_command 'Show all filename extensions' 'defaults write NSGlobalDomain AppleShowAllExtensions -bool true'
RESTART_FINDER=true
;;
3)
add_command 'Hide filename extensions' 'defaults write NSGlobalDomain AppleShowAllExtensions -bool false'
RESTART_FINDER=true
;;
esac
ask_choice 'Finder path bar' "$(read_default com.apple.finder ShowPathbar)" \
'Keep current setting' \
'Show path bar' \
'Hide path bar'
case "$CHOICE" in
2)
add_command 'Show Finder path bar' 'defaults write com.apple.finder ShowPathbar -bool true'
RESTART_FINDER=true
;;
3)
add_command 'Hide Finder path bar' 'defaults write com.apple.finder ShowPathbar -bool false'
RESTART_FINDER=true
;;
esac
ask_choice 'Full POSIX path as Finder window title' "$(read_default com.apple.finder _FXShowPosixPathInTitle)" \
'Keep current setting' \
'Show full path in title' \
'Hide full path in title'
case "$CHOICE" in
2)
add_command 'Show full POSIX path in Finder window title' 'defaults write com.apple.finder _FXShowPosixPathInTitle -bool true'
RESTART_FINDER=true
;;
3)
add_command 'Hide full POSIX path in Finder window title' 'defaults write com.apple.finder _FXShowPosixPathInTitle -bool false'
RESTART_FINDER=true
;;
esac
ask_choice 'Folders first when sorting by name' "$(read_default com.apple.finder _FXSortFoldersFirst)" \
'Keep current setting' \
'Keep folders on top' \
'Mix folders with files'
case "$CHOICE" in
2)
add_command 'Keep folders on top when sorting by name' 'defaults write com.apple.finder _FXSortFoldersFirst -bool true'
RESTART_FINDER=true
;;
3)
add_command 'Mix folders with files when sorting by name' 'defaults write com.apple.finder _FXSortFoldersFirst -bool false'
RESTART_FINDER=true
;;
esac
ask_choice 'Default location for new Finder windows' "$(read_default com.apple.finder NewWindowTarget)" \
'Keep current setting' \
'Desktop' \
'Home folder' \
'Documents' \
'Custom path'
case "$CHOICE" in
2)
add_command 'Open new Finder windows at Desktop' 'defaults write com.apple.finder NewWindowTarget -string "PfDe"; defaults write com.apple.finder NewWindowTargetPath -string "file://${HOME}/Desktop/"'
RESTART_FINDER=true
;;
3)
add_command 'Open new Finder windows at Home' 'defaults write com.apple.finder NewWindowTarget -string "PfHm"; defaults write com.apple.finder NewWindowTargetPath -string "file://${HOME}/"'
RESTART_FINDER=true
;;
4)
add_command 'Open new Finder windows at Documents' 'defaults write com.apple.finder NewWindowTarget -string "PfDo"; defaults write com.apple.finder NewWindowTargetPath -string "file://${HOME}/Documents/"'
RESTART_FINDER=true
;;
5)
local path=
local quoted_url=
printf 'Custom Finder path: '
read -r path
[ -n "$path" ] || fail 'Finder path cannot be empty.'
path=$(expand_user_path "$path")
quoted_url=$(shell_quote "file://$path/")
add_command "Open new Finder windows at $path" "defaults write com.apple.finder NewWindowTarget -string PfLo; defaults write com.apple.finder NewWindowTargetPath -string $quoted_url"
RESTART_FINDER=true
;;
esac
ask_choice 'Finder search scope' "$(read_default com.apple.finder FXDefaultSearchScope)" \
'Keep current setting' \
'Search current folder by default' \
'Search this Mac by default' \
'Use previous search scope'
case "$CHOICE" in
2)
add_command 'Search current folder by default in Finder' 'defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"'
RESTART_FINDER=true
;;
3)
add_command 'Search this Mac by default in Finder' 'defaults write com.apple.finder FXDefaultSearchScope -string "SCev"'
RESTART_FINDER=true
;;
4)
add_command 'Use previous Finder search scope' 'defaults write com.apple.finder FXDefaultSearchScope -string "SCsp"'
RESTART_FINDER=true
;;
esac
ask_choice 'Warning when changing file extension' "$(read_default com.apple.finder FXEnableExtensionChangeWarning)" \
'Keep current setting' \
'Show warning' \
'Disable warning'
case "$CHOICE" in
2)
add_command 'Show warning when changing a file extension' 'defaults write com.apple.finder FXEnableExtensionChangeWarning -bool true'
RESTART_FINDER=true
;;
3)
add_command 'Disable warning when changing a file extension' 'defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false'
RESTART_FINDER=true
;;
esac
ask_choice 'Create .DS_Store files on network volumes' "$(read_default com.apple.desktopservices DSDontWriteNetworkStores)" \
'Keep current setting' \
'Allow .DS_Store on network volumes' \
'Avoid .DS_Store on network volumes'
case "$CHOICE" in
2)
add_command 'Allow .DS_Store files on network volumes' 'defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool false'
;;
3)
add_command 'Avoid .DS_Store files on network volumes' 'defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true'
;;
esac
ask_choice 'Create .DS_Store files on USB volumes' "$(read_default com.apple.desktopservices DSDontWriteUSBStores)" \
'Keep current setting' \
'Allow .DS_Store on USB volumes' \
'Avoid .DS_Store on USB volumes'
case "$CHOICE" in
2)
add_command 'Allow .DS_Store files on USB volumes' 'defaults write com.apple.desktopservices DSDontWriteUSBStores -bool false'
;;
3)
add_command 'Avoid .DS_Store files on USB volumes' 'defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true'
;;
esac
ask_choice 'Default Finder view style' "$(read_default com.apple.finder FXPreferredViewStyle)" \
'Keep current setting' \
'Icon view' \
'List view' \
'Column view' \
'Gallery view'
case "$CHOICE" in
2)
add_command 'Use icon view in Finder by default' 'defaults write com.apple.finder FXPreferredViewStyle -string "icnv"'
RESTART_FINDER=true
;;
3)
add_command 'Use list view in Finder by default' 'defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv"'
RESTART_FINDER=true
;;
4)
add_command 'Use column view in Finder by default' 'defaults write com.apple.finder FXPreferredViewStyle -string "clmv"'
RESTART_FINDER=true
;;
5)
add_command 'Use gallery view in Finder by default' 'defaults write com.apple.finder FXPreferredViewStyle -string "glyv"'
RESTART_FINDER=true
;;
esac
ask_choice 'Save new documents to iCloud by default' "$(read_default NSGlobalDomain NSDocumentSaveNewDocumentsToCloud)" \
'Keep current setting' \
'Save to iCloud by default' \
'Save to disk by default'
case "$CHOICE" in
2)
add_command 'Save new documents to iCloud by default' 'defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool true'
;;
3)
add_command 'Save new documents to disk by default' 'defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false'
;;
esac
ask_choice 'Desktop drive and server icons' "external: $(read_default com.apple.finder ShowExternalHardDrivesOnDesktop), hard drives: $(read_default com.apple.finder ShowHardDrivesOnDesktop), servers: $(read_default com.apple.finder ShowMountedServersOnDesktop), removable: $(read_default com.apple.finder ShowRemovableMediaOnDesktop)" \
'Keep current setting' \
'Show hard drives, servers, and removable media' \
'Hide hard drives, servers, and removable media'
case "$CHOICE" in
2)
add_command 'Show drive, server, and removable media icons on 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'
RESTART_FINDER=true
;;
3)
add_command 'Hide drive, server, and removable media icons on 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'
RESTART_FINDER=true
;;
esac
}
configure_dock() {
info 'Dock'
ask_choice 'Dock autohide' "$(read_default com.apple.dock autohide)" \
'Keep current setting' \
'Enable autohide' \
'Disable autohide'
case "$CHOICE" in
2)
add_command 'Enable Dock autohide' 'defaults write com.apple.dock autohide -bool true'
RESTART_DOCK=true
;;
3)
add_command 'Disable Dock autohide' 'defaults write com.apple.dock autohide -bool false'
RESTART_DOCK=true
;;
esac
ask_choice 'Minimize windows using' "$(read_default com.apple.dock mineffect)" \
'Keep current setting' \
'Genie effect' \
'Scale effect'
case "$CHOICE" in
2)
add_command 'Use Genie minimize effect' 'defaults write com.apple.dock mineffect -string genie'
RESTART_DOCK=true
;;
3)
add_command 'Use Scale minimize effect' 'defaults write com.apple.dock mineffect -string scale'
RESTART_DOCK=true
;;
esac
ask_choice 'Dock icon size' "$(read_default com.apple.dock tilesize)" \
'Keep current setting' \
'36 px' \
'48 px' \
'64 px' \
'Custom size'
case "$CHOICE" in
2)
add_command 'Set Dock icon size to 36 px' 'defaults write com.apple.dock tilesize -int 36'
RESTART_DOCK=true
;;
3)
add_command 'Set Dock icon size to 48 px' 'defaults write com.apple.dock tilesize -int 48'
RESTART_DOCK=true
;;
4)
add_command 'Set Dock icon size to 64 px' 'defaults write com.apple.dock tilesize -int 64'
RESTART_DOCK=true
;;
5)
local size=
printf 'Dock icon size: '
read -r size
[[ "$size" =~ ^[0-9]+$ ]] || fail 'Dock icon size must be a number.'
add_command "Set Dock icon size to $size px" "defaults write com.apple.dock tilesize -int $size"
RESTART_DOCK=true
;;
esac
ask_choice 'Dock magnification' "$(read_default com.apple.dock magnification)" \
'Keep current setting' \
'Enable magnification' \
'Disable magnification'
case "$CHOICE" in
2)
add_command 'Enable Dock magnification' 'defaults write com.apple.dock magnification -bool true'
RESTART_DOCK=true
;;
3)
add_command 'Disable Dock magnification' 'defaults write com.apple.dock magnification -bool false'
RESTART_DOCK=true
;;
esac
ask_choice 'Dock magnification size' "$(read_default com.apple.dock largesize)" \
'Keep current setting' \
'96 px' \
'128 px' \
'160 px' \
'Custom size'
case "$CHOICE" in
2)
add_command 'Set Dock magnification size to 96 px' 'defaults write com.apple.dock largesize -int 96'
RESTART_DOCK=true
;;
3)
add_command 'Set Dock magnification size to 128 px' 'defaults write com.apple.dock largesize -int 128'
RESTART_DOCK=true
;;
4)
add_command 'Set Dock magnification size to 160 px' 'defaults write com.apple.dock largesize -int 160'
RESTART_DOCK=true
;;
5)
local size=
printf 'Dock magnification size: '
read -r size
[[ "$size" =~ ^[0-9]+$ ]] || fail 'Dock magnification size must be a number.'
add_command "Set Dock magnification size to $size px" "defaults write com.apple.dock largesize -int $size"
RESTART_DOCK=true
;;
esac
ask_choice 'Recent applications in Dock' "$(read_default com.apple.dock show-recents)" \
'Keep current setting' \
'Show recent applications' \
'Hide recent applications'
case "$CHOICE" in
2)
add_command 'Show recent applications in Dock' 'defaults write com.apple.dock show-recents -bool true'
RESTART_DOCK=true
;;
3)
add_command 'Hide recent applications in Dock' 'defaults write com.apple.dock show-recents -bool false'
RESTART_DOCK=true
;;
esac
}
configure_mission_control() {
info 'Mission Control'
ask_choice 'Mission Control animation speed' "$(read_default com.apple.dock expose-animation-duration)" \
'Keep current setting' \
'macOS default' \
'Fast, 0.1 seconds' \
'Custom duration'
case "$CHOICE" in
2)
add_command 'Restore default Mission Control animation speed' 'defaults delete com.apple.dock expose-animation-duration 2>/dev/null || true'
RESTART_DOCK=true
;;
3)
add_command 'Speed up Mission Control animations' 'defaults write com.apple.dock expose-animation-duration -float 0.1'
RESTART_DOCK=true
;;
4)
local duration=
printf 'Animation duration in seconds, for example 0.1: '
read -r duration
[[ "$duration" =~ ^[0-9]+([.][0-9]+)?$ ]] || fail 'Animation duration must be a number.'
add_command "Set Mission Control animation duration to $duration seconds" "defaults write com.apple.dock expose-animation-duration -float $duration"
RESTART_DOCK=true
;;
esac
ask_choice 'Dashboard as a Space' "$(read_default com.apple.dock dashboard-in-overlay)" \
'Keep current setting' \
'Do not show Dashboard as a Space' \
'Show Dashboard as a Space'
case "$CHOICE" in
2)