Skip to content

Instantly share code, notes, and snippets.

@benlind
Last active February 14, 2024 12:04
Show Gist options
  • Save benlind/7dc0e196a7ae59fa1d867bce153258fc to your computer and use it in GitHub Desktop.
Save benlind/7dc0e196a7ae59fa1d867bce153258fc to your computer and use it in GitHub Desktop.
New Mac Environment Setup

New Mac Environment Setup

These items are ordered by priority to reduce annoyance when first setting up a new mac.

TODO

Install Chrome

Log into iCloud

Do this in System Preferences.

Install 1Password

2021-09-10: We are stuck using 1Password 6 because version 7 requires a recurring subscription. Who knows how long version 6 will work and not delete my data. Go here to download version 6. After installing, select Sync with iCloud.

Then install the 1Password browser extension. This might automatically be done for you when you sign into Chrome. You will need to get the classic extension which doesn't require a 1Password account.

Set up Mac OS Preferences

  • General
    • Appearance: Dark
    • Sidebar icon size: Small
    • Click in the scroll bar to: Jump to the spot that's clicked
    • Close windows when quitting an app: off
  • Dock
    • Automatically hide and show dock: on
  • Mission Control
    • Keyboard and Mouse Shortcuts: none
    • Hot Corners:
      • Top left: none
      • Top right: none (RIP Dashboard)
      • Bottom right: Start Screen Saver
      • Bottom left: Desktop
  • Siri: disabled
  • Touch ID: Add both index fingers
  • Accessibility
    • Display > Cursor > Shake mouse pointer to locate: off
  • Security & Privacy
    • Unlock with Apple Watch: on
  • Sound
    • Play sound on startup: off
  • Keyboard
    • Keyboard
      • Key Repeat: fastest
      • Delay Until Repeat: one short of fastest
      • Touch Bar shows: Expanded Control Strip
    • Text
      • Correct spelling automatically: off
      • Capitalize words automatically: off
      • Add period with double-space: off
    • Shortcuts
      • Use keybaord navigation to move focus between controls: on
  • Trackpad
    • Point & Click
      • Tap to click: on
      • Click: Medium
      • Tracking speed: slightly above middle
      • Force Click: off
    • More Gestures
      • Swipe between pages: off
      • App Exposé: on
  • Mouse
    • Scroll direction: Natural
    • Secondary click: on
    • Tracking speed: two above middle
    • Mission Control: off
  • Displays
    • Night Shift: Sunset to Sunrise
  • Battery
    • Battery: Turn display off after 10 minutes

I tried UnnaturalScrollWheels because Scroll Reverser says it will one day be paid, but UnnaturalScrollWheels doesn't reverse magic mice.

Show hidden Finder files

Cmd + Shift + .

If you have a previous karabiner config saved in another computer's ~/.config/karabiner, you can copy that over to the new computer.

If setting up from scratch, go to Complex modifications > Add rule > Import from internet. Search for "Change caps_lock key (rev 5)" and click Import, then enable the "Change caps_lock to control if pressed with other keys, to escape if pressed alone" rule.

In the Parameters tab change to_if_alone_timeout_milliseconds to 500. I believe this will reduce the time I have to wait if I press Escape down by itself but decide I want to release it without triggering an escape.

If using an external keyboard, set up its custom keymappings.

Install Apptivate

I used to use a tool called Snap, but that was removed from the App Store (I could still download it from my purchase history but then it completely broken in Big Sur).

At one point Apptivate broke, but as of Sep 2021 it looks like it's fixed again. If in the future it breaks again here's a good SO post that has alternatives.

I use these shortcuts:

Shortcut App
⌘1 Google Chrome
⌘2 Mail or Gmail nativefier app
⌘3 Spotify
⌘4 DbVisualizer
⌘5 Postman
⌘6 Calendar
⌘7 Evernote
⌘8 iTerm
⌘⌃0 Finder
⌘⌃9 Microsoft To Do
⌘⌃' VS Code
⌘⇧1 Obsidian/Emacs
⌘⌥ + Tab Messages
⌘⌥` Slack or FB Messenger
⌘⌃; VPN
⌘⌥⌃c Color Picker
⌘⌥⌃k iCloud Drive > Automator > Dismiss All Notifications
⌘⌥⌃d iCloud Drive > Automator > Toggle Dark Mode

Configure iTerm

This comes bundled with Mac now.

I have uploaded some starter settings for iTerm here. Go to iTerm > Preferences > General and check "Load preferences from a custom folder or URL" to use this file.

Set up Emacs-like keyboard shortcuts everywhere

mkdir ~/Library/KeyBindings ; vim ~/Library/KeyBindings/DefaultKeyBinding.dict

Enter the following code:

{
  "^ " = setMark:;
  "^/" = undo:;
  "^w" = deleteToMark:;
  "^v" = pageDown:;
  "~b" = moveWordBackward:;
  "~c" = (capitalizeWord:, moveForward:, moveForward:);
  "~d" = deleteWordForward:;
  "~f" = moveWordForward:;
  "~l" = (lowercaseWord:, moveForward:, moveForward:);
  "~u" = (uppercaseWord:, moveForward:, moveForward:);
  "~v" = pageUp:;
  "~w" = (deleteToMark:, setMark:, yank:, swapWithMark:);
  "~B" = moveWordForwardAndModifySelection:;
  "~F" = moveWordForwardAndModifySelection:;
  "~ " = ("insertText:", " ");
}

(The "~ " one gets Mac to not insert non-breaking spaces on Opt + Space.)

You can verify that this worked by restarting Chrome and then doing Opt + F/B in the URL bar. It should do word forward/backward instead of printing glyphs.

Disable the press-and-hold for accents feature to enable key repeating:

defaults write -g ApplePressAndHoldEnabled -bool false

Install Flycut

This is a clipboard manager. You can find it on the Mac App Store. I use the hotkey Ctrl + Opt + V (it is a bit awkward because to cycle back in the clipboard history you have to shift your fingers around and hit shift, but I have yet to think of a better non-conflicting shortcut).

Enable iCloud syncing for settings.

Execute Settings Sync: Turn On... and sign in with GitHub.

To get code to work on the command line, add this to your ~/.zshrc file:

export PATH="$HOME/Applications/Visual Studio Code.app/Contents/Resources/app/bin:$PATH"

Configure git

  1. Generate a new SSH key: cd ~/.ssh && ssh-keygen
  2. ssh-add ~/.ssh/id_rsa
  3. Copy the id_rsa.pub contents to my GitHub profile
  4. git config --global user.name "Ben Lind"
  5. git config --global user.name "$email"
  6. git config --global pull.rebase true (rebase when pulling by default instead of creating merge commits)
  7. git config --global push.autoSetupRemote true (no need for git push -u origin $branch anymore)

Note: this includes installing Oh My Zsh.

Install Homebrew

If the Mac user you will be using most is not an admin and you don't want to have to su $adminUser every time you want to install new packages, you can instead install Homebrew in your homedir. See this SO question for that. This basically involved creating a ~/homebrew directory, cloning homebrew into it, and then running ~/homebrew/bin/brew doctor to set it up. Later make sure to add ~/homebrew/bin to your PATH.

To get Homebrew to install new applications in ~/Applications instead of /Applications:

echo 'export HOMEBREW_CASK_OPTS="--appdir=~/Applications"' >> ~/.zshrc

If you get this warning on zsh startup:

compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew

Run brew doctor to clean it up.

If you get Insecure completion-dependent directories detected from oh-my-zsh, see the shell setup README.

(Optional) Install homebrew git

Git already comes with Mac, but it's a slightly old version and it's nice to be able to update manually.

brew install git

Install Stay

Stay is a window manager that helps with multi-display setups. It will rearrange your open windows according to a config file whenever you connect or disconnect an external monitor.

Install Rectangle

Set up the "almost maximize" configuration:

defaults write com.knollsoft.Rectangle almostMaximizeHeight -float 1
defaults write com.knollsoft.Rectangle almostMaximizeWidth -float 0.8

Should be able to export/import the rest of the configs from another computer.

Keyboard shortcuts:

  • Left Half: ⌥⌘←
  • Right Half: ⌥⌘→
  • Center Half: ⌥⌘↓
  • Maximize: ⌥⇧⌘F
  • Almost Maximize: ⌥⌘↑
  • Maximize Height: ⌃⌥⇧↑
  • Center: ⌥⇧⌘C
  • Next Display: ⌥⇧⌘→
  • Previous Display: ⌥⇧⌘←

I used to use Spectacle but it was abandoned sometime before Sep 2021.

Install ack

brew install ack

Install Alfred

Disable the Spotlight Cmd + Space shortcut by going to the Spotlight pref pane, clicking Keyboard Shortcuts, and unchecking any associated shortcuts.

Set up app-specific shortcuts

In System Preferences > Keyboard > Shortcuts > App Shortcuts, add the following items:

App Menu Item Shortcut
Mail Insert Bulleted List ⇧⌘8
Add... ⌘K
Save Attachments... ⇧⌘S
Spotify Private Session ⌘P
Preview Adjust Size... ⌥⌘I
Google Chrome Bookmark This Tab... ⌥⇧⌘D

Set up desktop wallpapers

These are stored in iCloud Drive > Desktop Wallpapers. Download them and have each display randomly cycle through them.

Configure screenshots

Save to ~/Downloads:

defaults write com.apple.screencapture location ~/Downloads

Don't show the floating thumbnail (which delays the screenshot actually showing up in ~/Downloads by a few seconds) by hitting Cmd + Shift + 5, clicking Options, and un-checking the floating thumbnail option.

Install Day One

You can download the classic version from my app store purchase history (make sure it's "Day One Classic"). It should enable iCloud sync automatically, but to get the sync to trigger you can double-click on the iCloud > Journal_dayone file icon and then click the cloud download icon in Finder to start syncing.

Install other apps:

  • Backblaze
  • Covenant Eyes
  • Dropbox (for org files)
  • Microsoft To Do (from the Mac App Store)
  • Obsidian
    • Add a custom icon (iCloud Drive > obsidian icons)

Install Browser extensions

These should be auto-installed via the browser's sync process.

  • tabToWindow for moving tabs between windows. Change the "next window" keybinding to Cmd + Shift + S.
  • Tampermonkey (Chrome & Firefox). Set up settings sync to sync your scripts to Google Drive (I set this up for work but not yet for personal).
  • Stylus (Chrome & Firefox). Set up settings sync to sync your scripts to Google Drive (I set this up for work but not yet for personal).

Vimium (Chrome) or Vimium-FF (Firefox)

Use these custom key mappings:

# Insert your preferred key mappings here.

# On Mac, "alt-p" actually maps to the pi character
map <a-π> togglePinTab

unmap W
map <c-f> LinkHints.activateModeToOpenInNewForegroundTab

# Unmap commands that I often accidentally hit
unmap p

Install nvm

Install node

nvm install --lts

That should set the LTS version up as the default for you.

Update npm

nvm install-latest-npm

Install yarn

npm install --global yarn

Set up Electron apps with nativefier

yarn global add nativefier@42.4.0

Note (2021-06-28), version 43 and above seem to have broken the internal-urls feature for Gmail. So every link is treated as an internal URL. Maybe this is because of the way Gmail uses JS to open tabs and navigate to URLs (look at the saferedirect attribute of links in gmail). At some point in the future I can try to upgrade again.

  • Google Calendar: cd ~/Applications && nativefier --name "Google Calendar" "https://calendar.google.com/"
  • Gmail: cd ~/Applications && nativefier --name "Gmail" --internal-urls 'google\.com/a/grantstreet.com|accounts\.google\.com|google\.com/accounts' "https://mail.google.com/"

If you get an "old build detected" error for an app, you should be able to just rebuild the app with one of the above commands. If that doesn't work you may need to upgrade nativefier (but see note below):

  1. Quit the app
  2. Delete the app directory from /Applications
  3. Empty the trash
  4. Run yarn global upgrade --latest nativefier
  5. Repeat the appropriate installation command from above

Install qlstephen

This isn't Apple Silicon compatible yet. I'm watching this issue.

This lets you use QuickLook to preview text files like YAML, README, Makefile, etc.

The installation instructions are wrong: just run brew install qlstephen.

Hide Desktop icons

defaults write com.apple.finder CreateDesktop false && killall Finder

If that fails with Could not write domain com.apple.finder; exiting, then:

su blind-admin
sudo chown -R blind:staff /Users/blind/Library/Preferences/com.apple.finder.plist

Set up SMS text message forwarding from iPhone

Unless you do this, you will only be able to see/send iMessages from the Mac Messages app.

On your iPhone, go go Settings > Messages > Text Message Forwarding. Toggle the new computer on.

Set up Emacs

As of Feb 2022 I am now using Obsidian instead. However, I still install emacs according to the Doom docs for git commit editing (Vim doesn't have an easy way to wrap text). On 2022-05-18 I tried installing emacs from the Homebrew formulas that Doom recommends but they all failed with some Apple silicon specific errors. So I resorted to installing the "official" emacs distry via brew install emacs, which Doom says has compatibility issues with Doom.

I started using Doom on my personal computer in August 2020 and on my work computer in December 2020. I find it less awkwardly implemented than Spacemacs. It feels like it's working with core emacs instead of going against the grain. It is more easily customized and seems to have a more active repo. Oh, and it's faster.

In September 2021 I confirmed that these instructions work on Big Sur and with Homebrew installed in your home directory.

  1. Follow the Doom getting started docs. On my personal 2021 MacBook Pro on 2021-11-28 I was able to install the emacs-mac forumla which installed Emacs 27.2. On my work computer I previously installed Emacs 27 via the emacs-plus formula (make sure to run doom sync after installing emacs-plus). Moving forward try to use emacs-mac, since that's Doom's first recommendation.

  2. Delete the autogenerated ~/.doom.d directory.

  3. Clone my personal doom config into ~/.doom.d:

    git clone git@github.com:benlind/doom-emacs-config.git ~/.doom.d
    

    Note, this may require configuring your SSH key with GitHub: cat ~/.ssh/id_rsa.pub | pbcopy. Also try ssh-add ~/.ssh/id_rsa.

Notes from upgrading to Emacs 27 (and upgrading Doom), 2021-07-17

Doom emacs wasn't installing the neotree keyboard shortcuts (neither SPC o p and SPC o n were defined).

  1. I ran doom upgrade which first noted the old and new doom version commit hashes and asked for confirmation (I assume downgrading would be as easy as reverting the ~/.emacs.d to the old hash and running doom sync). I confirmed but then Doom said that it only support emacs 27 now and I was running emacs-plus@26.

  2. So I ran brew install emacs-plus@27, then had to force-link emacs-plus and replace my Emacs alias in /Applications with a link to /usr/local/Cellar/emacs-plus@27/27.2/Emacs.app/.

  3. Then I ran doom sync but that failed:

    (error . "Invalid value (1 single-branch) of depth for https://github.com/dimitri/el-get.git")
    
  4. I looked back at the Doom installation guide and ran brew install git ripgrep and then brew install coreutils fd.

  5. Homebrew told me that homebrew-core is a shallow clone and homebrew-cask is a shallow clone so I ran the commands it gave me and then brew update. That asked me to remove a few non-existent packages.

  6. I still got the above error, so I moved ~/.emacs.d to ~/.emacs.d-old-2021-07-17, re-cloned doom into ~/.emacs.d, and ran ~/.emacs.d/bin/doom install.

  7. I ran doom sync again and it worked this time! And Emacs 27 booted successfully. Woot.

Notes on installing "vanilla" Emacs 🏚

Note: I used this method (with my personal, hacky config) until I switched over to spacemacs in January 2020 (and then later Doom). You might still want to use this on a server.

Install the newest version of Emacs

The version of Emacs that ships with Mac is probably not a recent enough release. I recommend using Homebrew to install the newest version:

brew install emacs

Then, in order to get Mac to use this new version instead of the built-in one, add it to your PATH (replacing 25.1 with the Emacs version):

path=('/usr/local/Cellar/emacs/25.1/bin' $path)
export PATH

Set up the configs

Clone my Emacs config files into ~/.emacs.d/. This includes all necessary package files.

If the system you're on has an old emacs version and you can't upgrade it (you don't have sudo privileges), you can install the latest version of emacs from source in your home directory. You might need to do this if you want to use Magit, which requires emacs version 24.4 or later.

Set up emacs-anywhere

This lets you edit an input anywhere on your computer (e.g., Chrome) in emacs.

Run through the installation instructions. I used the keyboard shortcut Cmd + Ctrl + E.

All this tool really does is call emacsclient to open emacs. If you run into errors, try running emacsclient -c in the terminal and see if it does what you want emacs-anywhere to do.

When first setting this up I had to:

  • Create a ~/.bash_profile file (emacs-anywhere only consults that, not .zshrc) and add export EA_EDITOR='/usr/local/Cellar/emacs-plus@27/27.1/bin/emacsclient -a "" -c -d $DISPLAY'
  • Make sure your emacs config starts the emacs server. I added this to the top of my doom emacs config.el: (server-start)

Set up keyboard shortcut for dismissing all notifications

I discovered this workflow by starting with this SO thread, which linked to this gist.

At first I used a Services keyboard shortcut to trigger this workflow, but that was slow and didn't work in Electron apps. Then I figured out that I could use Apptivate for this.

  1. Add a new Apptivate shortcut
  2. Select iCloud Drive > Automator > Dismiss All Notifications
  3. Use the keyboard shortcut ⌘⌥⌃k

Hush the terminal's "last login" message

touch ~/.hushlogin

Backing up a Computer

Here are some things you should make sure to back up before wiping a hard drive:

  • TamperMonkey scripts
  • Stylus styles
  • Home directory dotfiles (e.g., ~/.shell/work)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment