Skip to content

Commit 0a0570e

Browse files
committed
[macOS] Update settings and automatically install QuickLook plugins
1 parent 4ca9d1e commit 0a0570e

File tree

4 files changed

+102
-53
lines changed

4 files changed

+102
-53
lines changed

CHECKLIST.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Manual steps that are still done on every new setup:
99

1010
Then, in no particular order:
1111

12+
- System Preferences > Keyboard > Key Repeat > Fast.
13+
14+
- System Preferences > Keyboard > Delay Until Repeat > Short.
15+
1216
- System Preferences > Keyboard > Modifier Keys... > Caps Lock Key > Control.
1317

1418
- System Preferences > Display > Night Shift > Schedule > Sunset to Sunrise.

defaults.yaml

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@ NSGlobalDomain:
99
# Disable press and hold character picker.
1010
ApplePressAndHoldEnabled: false
1111

12-
# System Preferences > Keyboard > Key Repeat.
13-
KeyRepeat: 1
14-
15-
# System Preferences > Keyboard > Delay Until Repeat.
16-
InitialKeyRepeat: 15
17-
18-
# Disable smooth scrolling
12+
# Disable smooth scrolling.
1913
NSScrollAnimationEnabled: false
2014

2115
com.apple.desktopservices:
@@ -51,9 +45,6 @@ com.apple.finder:
5145
# Finder > Preferences > Show these items on the desktop > Hard disks.
5246
ShowHardDrivesOnDesktop: false
5347

54-
# Finder > View > Show Path Bar.
55-
ShowPathbar: true
56-
5748
com.apple.iTunes:
5849
# iTunes > Preferences > Devices > Prevent iPods, iPhones, and iPads from
5950
# syncing automatically.
@@ -92,32 +83,23 @@ com.apple.TextEdit:
9283
# TextEdit > Preferences > New Document > Plain text.
9384
RichText: false
9485

86+
com.apple.Terminal:
87+
# Terminal > Secure Keyboard Entry.
88+
SecureKeyboardEntry: true
89+
90+
# Set custom theme as default.
91+
"Default Window Settings": Zenburn
92+
"Startup Window Settings": Zenburn
93+
9594
com.apple.SoftwareUpdate:
96-
# System Preferences > Software Update > Advanced... > Automatically check for
97-
# updates.
95+
# System Preferences > Software Update > Advanced... > Automatically check
96+
# for updates.
9897
AutomaticCheckEnabled: true
9998

10099
# System Preferences > Software Update > Advanced... > Download new updates
101100
# when available.
102101
AutomaticDownload: true
103102

104-
com.flexibits.fantastical2.mac:
105-
# Fantastical 2 > Preferences > Appearance > Hide Fantastical in Dock.
106-
HideDockIcon: true
107-
108-
# Fantastical 2 > Preferences > General > Record Shortcut > None.
109-
HotKeyEmpty: true
110-
111-
# Fantastical 2 > Preferences > Advanced > Open maps in: Google Maps.
112-
OpenMapsIn: google
113-
114-
# Fantastical 2 > Preferences > Appearance > Menu bar icon shows: Nothing.
115-
StatusItemBadge: StatusItemStyleNone
116-
117-
com.kapeli.dashdoc:
118-
# Dash > Preferences > General > Behavior > Show dock icon > Off.
119-
showInDock: false
120-
121103
org.gnu.Emacs:
122104
# Enable natural title bar patch for Emacs.
123105
TransparentTitleBar: DARK

run/after/z_macos_setup.sh

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,15 @@ trap 'rm -rf "$REPOS_DIR"' EXIT
2323
set +x
2424
)
2525

26-
# Use a modified version of the Zenburn theme by default in Terminal.app
27-
# Originally taken from https://github.com/bdesham/zenburn-terminal
28-
echo "Setting default Terminal theme..."
29-
30-
open -a Terminal "$SCRIPT_DIR/../lib/assets/Zenburn.terminal"
31-
sleep 2 # Wait a bit for theme to install.
32-
osascript -e 'tell application "Terminal"' \
33-
-e 'set default settings to settings set "Zenburn"' \
34-
-e "close window 1" \
35-
-e "end tell"
36-
3726
echo "Updating Dock..."
3827

28+
set -x
3929
dockutil --remove all --no-restart
40-
dockutil --add /Applications/Alacritty.app --no-restart
41-
dockutil --add /Applications/Emacs.app --no-restart
4230
dockutil --add /Applications/Firefox.app --no-restart
31+
dockutil --add /Applications/Emacs.app --no-restart
32+
dockutil --add /Applications/Alacritty.app --no-restart
4333
dockutil --add ~/Downloads --display stack # Implicitly restarts the Dock.
34+
set +x
4435

4536
echo "Updating default application handlers..."
4637

@@ -68,24 +59,52 @@ duti -s org.gnu.Emacs public.xml all
6859
duti -s org.gnu.Emacs public.yaml all
6960
set +x
7061

71-
echo "Applying icons..."
62+
(
63+
cd "$SCRIPT_DIR/../lib"
7264

73-
if ! command -v chicon >/dev/null; then
74-
set -x
75-
brew install https://raw.githubusercontent.com/okdana/chicon/d602584/pkg/chicon.rb
76-
set +x
77-
fi
65+
echo "Adding Terminal theme..."
66+
if ! defaults read com.apple.Terminal "Window Settings" | grep -Fw Zenburn >/dev/null; then
67+
open -a Terminal assets/Zenburn.terminal
68+
fi
69+
70+
echo "Applying icons..."
71+
./set-icon assets/Alacritty.icns /Applications/Alacritty.app
72+
./set-icon assets/Emacs.icns /Applications/Emacs.app
7873

79-
chicon "$SCRIPT_DIR/../lib/assets/Alacritty.icns" /Applications/Alacritty.app
80-
chicon "$SCRIPT_DIR/../lib/assets/Emacs.icns" /Applications/Emacs.app
74+
echo "Installing custom utilities..."
75+
./KeyBindings/install
76+
./LaunchTerm/install
77+
)
8178

82-
echo "Installing custom utilities..."
79+
echo "Adding applications to Gatekeeper whitelist..."
80+
(while read -r app; do
81+
spctl --remove "$app" 2>/dev/null ||:
82+
spctl --add "$app"
83+
echo "Whitelisted $app."
84+
done) <<-EOF
85+
/Applications/Alacritty.app
86+
/Applications/Chromium.app
87+
/Applications/Pine.app
88+
$HOME/Library/QuickLook/Pacifist.qlgenerator
89+
$HOME/Library/QuickLook/QLColorCode.qlgenerator
90+
$HOME/Library/QuickLook/QLStephen.qlgenerator
91+
EOF
8392

84-
"$SCRIPT_DIR/../lib/KeyBindings/install"
85-
"$SCRIPT_DIR/../lib/LaunchTerm/install"
93+
echo "Resetting QuickLook."
94+
set -x
95+
qlmanage -r
96+
qlmanage -r cache
97+
killall Finder
98+
set +x
99+
100+
echo "Disabling Homebrew analytics."
101+
set -x
102+
brew analytics off
103+
set +x
86104

87105
echo "Disabling netbiosd."
88106
set -x
89107
sudo launchctl disable system/netbiosd
90108
sudo launchctl unload -w /System/Library/LaunchAgents/com.apple.netbiosd.plist 2>/dev/null
91109
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.netbiosd.plist 2>/dev/null
110+
set +x

run/lib/set-icon

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/swift
2+
import AppKit
3+
import Darwin
4+
5+
extension NSWorkspace {
6+
func setIcon(fileURL: URL, iconURL: URL?) throws -> Bool {
7+
let icon = iconURL.map(NSImage.init)
8+
_ = try fileURL.checkResourceIsReachable()
9+
_ = try iconURL?.checkResourceIsReachable()
10+
return setIcon(icon, forFile: fileURL.relativePath, options: [])
11+
}
12+
}
13+
14+
func main() {
15+
if CommandLine.argc != 3 {
16+
fputs("Error: Invalid number of arguments.\n", stderr)
17+
exit(1)
18+
}
19+
20+
let iconURL: URL? = URL(fileURLWithPath: CommandLine.arguments[1])
21+
let fileURL: URL = URL(fileURLWithPath: CommandLine.arguments[2])
22+
do {
23+
guard try NSWorkspace.shared.setIcon(fileURL: fileURL, iconURL: iconURL) else {
24+
fputs("Error: Could not set icon for \(fileURL.relativePath)\n", stderr)
25+
exit(1)
26+
}
27+
28+
print("Successfully set icon for \(fileURL.relativePath).")
29+
} catch {
30+
var statusCode: Int = 1
31+
let nsError: NSError = error as NSError
32+
if nsError.domain == NSPOSIXErrorDomain {
33+
statusCode = nsError.code
34+
} else if let underlyingError = nsError.userInfo[NSUnderlyingErrorKey] as? NSError,
35+
underlyingError.domain == NSPOSIXErrorDomain {
36+
statusCode = underlyingError.code
37+
}
38+
fputs("Error: Could not set icon for \(fileURL.relativePath). " +
39+
"\(error.localizedDescription)\n", stderr)
40+
exit(Int32(statusCode))
41+
}
42+
}
43+
44+
main()

0 commit comments

Comments
 (0)