Setting up my MacBook

Disable [rootless]

System Integrity Protection ("rootless") prevents some directories and files from being modified even by the root user.

Some programs do not work well with SIP enabled. Do the following to disable it:

  • Enter Recovery Mode: Start by pressing Command ⌘ + R
  • Open the terminal: Utilities » Terminal
  • Run the command csrutil disable
SIP is a security mechanism and should be re-enabled when possible.

Root Password:

sudo passwd

Hostname

sudo scutil --set ComputerName "Air"
sudo scutil --set HostName "Air"
sudo scutil --set LocalHostName "Air"
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server.plist NetBIOSName -string "Air"

Trackpad

Three-finger Drag

Accessibility » Mouse & Trackpad » Trackpad Options… » Enable dragging » three finger drag

Scanner

Xsane, which I use on Linux, also works on Mac. It is open source and quite comprehensive:

brew install sane-backends
brew install xsane

Vuescan is a native app and works very well, but it is paid.

Zoom

Accessibility » Zoom » Use scroll gesture with modifier keys to zoom: ^ Control

XCode

The latest version of XCode can be downloaded from the Apple Store or at https://developer.apple.com/downloads/, where beta versions are also available.

If the .xip file downloaded from the Apple website appears to be corrupted, try opening it with another program. Here, The Unarchiver showed “Data Corrupted,” but it worked perfectly with the Archive Utility.

Install the command line tools:

xcode-select --install
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

Open XCode and accept the license agreement or type “agree” in sudo xcodebuild -license to agree.

Disable Gatekeeper to allow installing applications downloaded from the internet

Resolve the “XXX can’t be opened because it is from an unidentified developer”.

sudo spctl --master-disable

System Preferences > Security & Privacy > General » Allow apps downloaded from: Anywhere.

Re-enable with: sudo spctl --master-enable.

Dotfiles

git clone --recursive https://github.com/jbsilva/dotfiles.git

cd dotfiles

git submodule update --init --recursive

Homebrew

Download and install Homebrew:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew tap Homebrew/bundle

brew bundle --file=/Users/julio/dotfiles/Brewfile

Karabiner-Elements

Download Karabiner-Elements

Some advanced modifications can be found at https://ke-complex-modifications.pqrs.org/.

Swap Caps-Lock with ESC

The configuration is in the dotfiles.

Use Enter in Finder to enter a directory

Use F2 to rename

Zplug + Zprezto

Zplug manages ZSH plugins. It is installed automatically.

ln -s ~/dotfiles/.gitconfig ~
ln -s ~/dotfiles/.config ~
ln -s ~/dotfiles/.zsh ~
ln -s ~/dotfiles/.zshrc ~
sudo cp ~/dotfiles/fstab /etc/fstab

Zsh default shell

command -v zsh | sudo tee -a /etc/shells
sudo chsh -s "$(command -v zsh)" "${USER}"
compaudit | xargs chmod g-w

Zsh completions

Install the zsh_completions formula:

brew install zsh-completions

Add $(brew --prefix)/share/zsh-completions to $FPATH:

FPATH=$(brew --prefix)/share/zsh-completions:$FPATH

Mounting HD

Create the indicated folder in /etc/fstab and mark it as unchangeable so that MacOS does not delete it after the disk is unmounted:

sudo mkdir /Volumes/Elements
sudo chflags uchg /Volumes/Elements/

Mount the disk:

diskutil mount disk2s1

Vim

Vundle

Open Vim and download the plugins: :PluginInstall

Spell checker

Type :setlocal spell spelllang=pt_br in Vim and follow the instructions.

Finder

  • In Home (~)
    • View » Show View Options (Cmd+J):
      • Calculate all sizes,
      • Show Library Folder,
      • Show item info
  • On Desktop
    • Right-click » Show View Options (Cmd+J):
      • Show item info,
      • Increase Grid spacing

Prevent automatic sleep

There are several programs for this function:

  • InsomniaX
  • Caffeine
  • Amphetamine
  • KeepingYouAwake

I’m using KeepingYouAwake, which is very simple and free.

Through the command line, there is caffeinate:

Prevent sleep for 1 hour (3600 seconds):

caffeinate -u -t 3600

Prevent sleep until the command completes:

caffeinate -s command

Prevent sleep until Ctrl-C:

caffeinate -I

Prevent sleep when closing the lid

sudo pmset -a disablesleep 1

Disable HD sleep

System Preferences » Energy Saver: uncheck Put hard disks to sleep when possible

ln -s /Volumes ~/Desktop/

Disable guest user

System Preferences » Users & Groups: Uncheck “Allow guest to log in to this computer”.

SSH

Copy your backup keys and give the appropriate permissions:

cp -r /Volumes/Cofre/.ssh ~
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chmod 600 ~/.ssh/*
chmod 644 ~/.ssh/*.pub

Spotlight

System Preferences » Spotlight

Spotlight returns quite useless things in search results. Disable Bookmarks & History, Fonts, Movies, Music, Other, Presentations, etc.

Uncheck “Allow Spotlight Suggestion in Look up”.

NTFS

NTFS-3g

OSXFUSE and NTFS-3g can be installed for free via Homebrew.

Link mount_ntfs to ntfs-3g:

sudo mv /sbin/mount_ntfs /sbin/mount_ntfs.original
sudo ln -s /usr/local/sbin/mount_ntfs /sbin/mount_ntfs

Paragon and Tuxera

I used NTFS-3g for many years (both on Linux and Mac), but its performance really leaves much to be desired.

I switched to Paragon when I needed to back up a few terabytes of data. The difference in transfer rate was quite significant.

Consider Paragon ($34.95) or Tuxera ($107.13) if you use NTFS-formatted disks.

Python

Virtualenv

$ export PYTHON_CONFIGURE_OPTS="--enable-framework --enable-unicode=ucs4 --enable-ipv6 --enable-loadable-sqlite-extensions"
$ pyenv install 2.7-dev
$ pyenv install 3.7-dev
$ pyenv rehash
$ pyenv global 2.7-dev 3.7-dev

The framework support (--enable-framework) is necessary for tools like YouCompleteMe.

Python libs

pip3 install flake8 ipython matplotlib numpy pep8 pep8-naming pygments scipy unidecode mako coursera awscli neovim

Ruby

Ruby version manager (RVM)

curl -L https://get.rvm.io | bash -s stable --rails

Gems

gem install pygmentize

Defaults

Trackpad and Mouse

Natural scrolling

defaults write NSGlobalDomain com.apple.swipescrolldirection -bool true

Tap to click

defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true
defaults write NSGlobalDomain com.apple.mouse.tapBehavior -int 1

Right-click

defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadCornerSecondaryClick -int 0
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadRightClick -bool true
defaults -currentHost write NSGlobalDomain com.apple.trackpad.trackpadCornerClickBehavior -int 0
defaults -currentHost write NSGlobalDomain com.apple.trackpad.enableSecondaryClick -bool true

Keyboard

Enable tab in modal dialogs

defaults write NSGlobalDomain AppleKeyboardUIMode -int 3

Language

defaults write NSGlobalDomain AppleLanguages -array "en" "de" "pt-BR"

defaults write NSGlobalDomain AppleLocale -string "pt_BR@currency=BRL"

defaults write NSGlobalDomain AppleMeasurementUnits -string "Centimeters"

defaults write NSGlobalDomain AppleMetricUnits -bool true

Enable Debug menu in App Store

defaults write com.apple.appstore ShowDebugMenu -bool true

Folder where screenshots will be saved

SCREENSHOTS="${HOME}/Desktop/Screenshots" && mkdir "${SCREENSHOTS}" && defaults write com.apple.screencapture location -string "${SCREENSHOTS}"

Enable key repeat when holding down a key (requires restart)

    $ defaults write -g ApplePressAndHoldEnabled -bool false

Faster key repeat rate

    $ defaults write NSGlobalDomain KeyRepeat -int 2

Open Finder at home (~/)

    $ defaults write com.apple.finder NewWindowTarget -string "PfLo"
    $ defaults write com.apple.finder NewWindowTargetPath -string "file://${HOME}"

Show path bar in Finder

    $ defaults write com.apple.finder ShowPathbar -bool true

Show status bar in Finder

    $ defaults write com.apple.finder ShowStatusBar -bool true

Does not warn about extension change

    $ defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false

Checks for updates daily (default: one week)

    $ defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1

Displays internal HDs icon on the desktop

    $ defaults write com.apple.finder ShowHardDrivesOnDesktop -bool true

Displays external HDs icon on the desktop

    $ defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true

Displays removable media icon on the desktop

    $ defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true

Displays servers icon on the desktop

    $ defaults write com.apple.finder ShowMountedServersOnDesktop -bool true

Does not create .DS_Store on network volumes

    $ defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true

Activates the development menu and Web Inspector in Safari

    defaults write com.apple.Safari IncludeInternalDebugMenu -bool true && \
    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 && \
    defaults write NSGlobalDomain WebKitDeveloperExtras -bool true

Shows absolute path in Finder title bar

    $ defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES

Displays ~/Library

    $ chflags nohidden ~/Library

Default Apps

Manually

    $ vim ~/Library/Preferences/com.apple.LaunchServices.plist

Duti

    $ duti -s org.videolan.vlc .mp4 all

Activates CUPS web interface

    $ sudo cupsctl WebInterface=yes

The server will be available at http://localhost:631/admin.

Lock screen

System Preferences » Security & Privacy » General » Require Password » 5 seconds

Lock: Control + Shift + Power Sleep: Command ⌘ + Option ⌥ + Power

Shortcut: System Preferences » Keyboard » Shortcuts » + » Lock Screen » Shortcut

iTerm2

Terminal colorscheme

Apply Zenburn

$ wget https://raw.githubusercontent.com/mbadolato/iTerm2-Color-Schemes/master/schemes/Zenburn.itermcolors

Command ⌘ + i » Colors » Color Presets » Import… » Zenburn.itermcolors » Open General » Copy Current Settings to Selected Profile.

Font

The Nerd Fonts package was installed via Homebrew. To use it in iTerm2, follow these steps:

Preferences » Profiles » Text » Non-ASCII Font » Hack Regular Nerd Font Complete

Login Items

System Preferences » Users & Groups » Current User » Login Items

Keep only:

  • Flux
  • InsomniaX (or equivalent)
  • SwitchResX Daemon
  • Moom

Chrome as default browser

xdg-mime default chromium.desktop x-scheme-handler/http
xdg-mime default chromium.desktop x-scheme-handler/https

Mute Chrome

In the address bar: chrome://flags/#enable-tab-audio-muting

Hosts

I have a script that downloads the hosts file from someonewhocares.org and installs it automatically:

sudo ~/dotfiles/hosts.sh

An application that helps manage the hosts file is GasMask:

brew cask install gas-mask

Dock

Keep only useful programs in the Dock:

  • Finder
  • Mail
  • Contacts
  • Calendar
  • iTerm
  • Google Chrome

Spotify

In addition to logging into Spotify, you also need to set up scrobbling to Last.fm: Preferences » Connect to Last.fm

Preferences: Disable “Local Files”

Tips

Avoid separate cover in Two Page view in Preview

Whenever you display a PDF with two pages per view, Preview will show the first page separately as if it were the cover of a book. Sometimes this is not what we want and there is no way to disable this “feature”, but there is a trick: insert a blank page and move it as the first page: Edit » Insert » Blank Page; View » Contact Sheet drag the blank page to the first position.

Scroll in terminal

Shift+fn+UP and Shift+fn+DOWN

Mail

Setting up Gmail emails is straightforward, but besides them, I also use an email from my own host.

If Mail does not automatically recognize the function of each imap folder, it will need to be defined manually. Ex.:

Select Deleted Messages » Mailbox » Use This Mailbox As » Trash Mailbox

PATH

Check if the order of directories in /etc/paths is correct and all directories are present.

Programs installed without Homebrew

  • Adobe Acrobat Pro or PDF Expert: PDF viewing and editing
  • Adobe Lightroom: Organize photo gallery
  • Adobe Photoshop: Image editing
  • CleanMyMac: System maintenance
  • Dash: API Documentation Browser
  • iStat Menu: Menu bar with CPU/Memory/Network/etc status
  • LittleSnitch: Blocks unwanted connections. Free alternative: Lulu
  • MacPaw Gemini: Removes duplicate files
  • Microsoft Office
  • Many Tricks Moom: Window management
  • Parallels: Virtualization
  • SideSync: Manage Samsung devices
  • SwitchResX: Screen resolution
  • Vuescan: scanner (free alternative: xsane)
  • Wunderlist

Firewall

OS X comes with pfctl. LittleSnitch and Lulu also allow managing outbound connections.

SSL Certificates

In my case, I have to add the certificates from the university: moodle.dc.ufscar.br

MySQL

CLI

brew install mysql
mysql.server start
mysql_secure_installation
mysql_upgrade -u root -p
mysql.server restart
$ mysql -u root -p
  mysql> select host, user, password from mysql.user;
  mysql> CREATE USER 'julio'@'localhost' IDENTIFIED BY '123456';
  mysql> GRANT ALL PRIVILEGES ON *.* TO 'julio'@'localhost' WITH GRANT OPTION;
  mysql> show variables;
  mysql> show databases;
  mysql> use nome_do_esquema;
$ mysql.server stop

MySQL Workbench

brew cask install mysqlworkbench

Apache

Uncomment the following lines in /etc/apache2/httpd.conf:

LoadModule authz_core_module libexec/apache2/mod_authz_core.so
LoadModule authz_host_module libexec/apache2/mod_authz_host.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule cgi_module libexec/apache2/mod_cgi.so
User folder

Uncomment the following lines in /etc/apache2/httpd.conf:

LoadModule userdir_module libexec/apache2/mod_userdir.so
Include /private/etc/apache2/extra/httpd-userdir.conf

Uncomment the following line in /etc/apache2/extra/httpd-userdir.conf:

Include /private/etc/apache2/users/*.conf

Create the file /etc/apache2/users/julio.conf:

<Directory "/Users/julio/Sites/">
    Options Indexes MultiViews FollowSymLinks
    Require all granted
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Restart Apache with sudo apachectl restart.

Create the ~/Sites folder:

mkdir ~/Sites

PHP

sudo cp /etc/php.ini.default /etc/php.ini
sudo -e /etc/php.ini

phpMyAdmin

sudo vim /etc/apache2/httpd.conf
Alias /phpmyadmin /usr/local/share/phpmyadmin
<Directory /usr/local/share/phpmyadmin/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    <IfModule mod_authz_core.c>
        Require all granted
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Allow from all
    </IfModule>
</Directory>

Google KSFetch

Google checks for updates every hour. Change this to 7 days:

defaults write com.google.Keystone.Agent checkInterval 604800

Or disable the check completely:

defaults write com.google.Keystone.Agent checkInterval 0

iTerm2 + tmux

iTerm2 is integrated with tmux, a terminal multiplexer.

Install via homebrew:

brew install tmux

Control mode:

tmux -CC

Byobu

Better than screen and tmux

Update: also consider Zellij.

Date

Date & Time:

  • Use a 24-hour clock,
  • Show the day of the week,
  • Show date

iBooks

Every time you open an .epub, iBooks copies it to the directory /Users/julio/Library/Containers/com.apple.BKAgentService/Data/Documents/iBooks.

The original is kept where it was. It may be useful to delete the files (through iBooks itself) to save space.

Inline attachment viewing type:

defaults write com.apple.mail DisableInlineAttachmentViewing -bool yes
defaults write com.apple.mail DisableInlineAttachmentViewing -bool false

Github

git config --global credential.helper osxkeychain

This is already configured in ~/.gitconfig.

Dictionaries

Dict.cc

Download from http://www.dict.cc/?s=about%3Awordlist

iStat Menus

Settings » Date & Time:

  • Uncheck Show date and time in menu bar.

Settings » Energy Saver:

  • Uncheck Show battery status in menu bar.

Rearrange menu items by dragging them while holding the Command (⌘) key.

Skype

Skype » Preferences… » Save files in: ~/Downloads/Skype

Telegram

Telegram » Preferences… » Advanced Settings » Save documents to: ~/Download/Telegram


Julio Batista Silva
Julio Batista Silva
Data Engineer

I’m a computer engineer passionate about science, technology, photography, and languages. Currently working as a Data Engineer in Germany.

comments powered by Disqus