0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Macの設定の半自動化方法

Last updated at Posted at 2022-01-31

Macで、初期設定をある程度自動化したい。
必要なアプリのインストールとか。

以下あたりを参考にしてスクリプトを作成したのでメモとして残しておく。
https://qiita.com/7coAim/items/fe8ac542a78f9f985572

https://kiririmode.hatenablog.jp/entry/20200103/1578033722

試したのはMacの11.4

システムの環境設定

defaultsコマンドで行える。

# タップでクリックとドラッグ(DragLock)を許可
defaults write com.apple.AppleMultitouchTrackpad Clicking -bool true
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true
defaults -currentHost write -g com.apple.mouse.tapBehavior -bool true
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Dragging -bool true
defaults write com.apple.AppleMultitouchTrackpad Dragging -bool true

# タッチバーをファンクションキーにする
defaults write com.apple.touchbar.agent PresentationModeGlobal -string functionKeys

# Finder:隠しファイル/フォルダを表示
defaults write com.apple.finder AppleShowAllFiles true

# Finder:拡張子を表示
defaults write NSGlobalDomain AppleShowAllExtensions -bool true

defaults以外だと以下のような設定がある

# 起動音なくす
sudo nvram StartupMute=%01

なお、ディスクの暗号化はfdesetupコマンドがあるが、ユーザ名の入力等は必要になるので、
これだけだと完全自動化はできなさそう。(Ansibleとかあればいけるのかも?)
(まぁ、暗号化はルートユーザ、それ以外は個別ユーザというやり方もあるので、すべて自動化でなくてもいいかも)

sudo fdesetup enable

キッティングの場合はこことかが参考になる。
MDM利用の場合は構成プロファイルを使う手がある。

アプリ関係

とりあえずHomeBerwを入れる。
https://brew.sh/index_jaのコマンドを実行。
2022年1月だと以下だった。

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

echo 'export PATH=/opt/homebrew/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile
echo 'export PATH=/opt/homebrew/bin:$PATH' >> ~/.zshrc
source ~/.zshrc

必要なソフトを入れる

# Chrome
brew cask install google-chrome

# VSCode
brew install visual-studio-code --cask
echo 'export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin:$PATH"` >>  ~/.bash_profile
source ~/.bash_profile
echo 'export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin:$PATH"` >>  ~/.zshrc
source ~/.zshrc
# 略

# VScodeの拡張例
code --install-extension ms-ceintl.vscode-language-pack-ja

nodebrewでのインストールや切り替え方はこことか参照。
pyenvはこことか

Homebrewは
途中でWifiが切れて、再度homebrewのインストールコマンドを流すとエラーになった。
error: Not a valid ref: refs/remotes/origin/master
これば
rm -rf /opt/homebrew
で一度削除してから実行で行けた。

一部は手動で良いので、.shは次のような形で一旦完成形としておいた。

macInstall.sh
# 再起動が必要なものもあり

# スリープとスクリーンセーバの解除にパスワードを要求
defaults write com.apple.screensaver askForPassword -bool true

# パスワードを要求するまでの秒数
defaults write com.apple.screensaver askForPasswordDelay -int 600

# Dockに最近使ったもの、を表示しない
defaults write com.apple.dock show-recents -bool false

# タップでクリックとドラッグを許可
defaults write com.apple.AppleMultitouchTrackpad Clicking -bool true
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true
defaults -currentHost write -g com.apple.mouse.tapBehavior -bool true
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Dragging -bool true
defaults write com.apple.AppleMultitouchTrackpad Dragging -bool true

# スペルミス修正しない
defaults write -g NSAutomaticSpellingCorrectionEnabled -bool false

# タッチバーをファンクションキーにする
defaults write com.apple.touchbar.agent PresentationModeGlobal -string functionKeys

# Finder:隠しファイル/フォルダを表示
defaults write com.apple.finder AppleShowAllFiles true

# Finder:拡張子を表示
defaults write NSGlobalDomain AppleShowAllExtensions -bool true

# CapsLock を Ctrl に変更することもコマンドから出来るらしい
# どちらかといえばCtrlではなくCommand=30064771299の方がいい気がしたので
keyboard_id="$(ioreg -c AppleEmbeddedKeyboard -r | grep -Eiw "VendorID|ProductID" | awk '{ print $4 }' | paste -s -d'-\n' -)-0"
defaults -currentHost write -g com.apple.keyboard.modifiermapping.${keyboard_id} -array-add "
<dict>
  <key>HIDKeyboardModifierMappingDst</key>\
  <integer>30064771299</integer>\
  <key>HIDKeyboardModifierMappingSrc</key>\
  <integer>30064771129</integer>\
</dict>
"

# 起動音なくす
sudo nvram StartupMute=%01


# home-brew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'export PATH=/opt/homebrew/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile
echo 'export PATH=/opt/homebrew/bin:$PATH' >> ~/.zshrc
source ~/.zshrc

# Chrome
brew install cask
brew install google-chrome --cask

# VSCode
brew install visual-studio-code --cask
echo 'export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin:$PATH"` >>  ~/.bash_profile
source ~/.bash_profile
echo 'export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin:$PATH"` >>  ~/.zshrc
source ~/.zshrc

# git appleGitではなくこちらを使う
# https://hirooooo-lab.com/development/install-git-by-homebrew/
brew install git

# node.js
brew install nodebrew
echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile
echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.zshrc
source ~/.zshrc
# https://qiita.com/sabinuki/items/3e5dd9285ceb8405e7f0
/opt/homebrew/opt/nodebrew/bin/nodebrew setup_dirs
nodebrew install-binary latest

# Python
brew install pyenv 
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
source ~/.bash_profile
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.zshrc
source ~/.zshrc
# インストールできるバージョンはpyenv install --listで確認可能
pyenv install 3.10.2
pyenv global 3.10.2

# UnityHub (本体はHubから手でインストール)
brew install unity-hub --cask

# VScodeの拡張
code --install-extension ms-dotnettools.csharp
code --install-extension Unity.unity-debug
code --install-extension kleber-swf.unity-code-snippets
code --install-extension mhutchie.git-graph
code --install-extension mosapride.zenkaku
code --install-extension k--kato.docomment
code --install-extension ms-ceintl.vscode-language-pack-ja

ターミナルからこのシェルを実行するが、その際にはchmodで実行権限を付ける。

それ以外

(https://auto-worker.com/blog/?p=2847)[https://auto-worker.com/blog/?p=2847]
IMEの入力設定は変更してライブ変換OFF、Windows風をONにした方が個人的には使いやすいが、コマンドラインでのやり方がよくわからなかったので手動切り替えした。

VSCode周りはhttps://zenn.dev/nmrtkhs/articles/0b75959281c9a7とかを確認。

VSCodeで補完するためにmonoをインストールした後は

echo 'export PATH=/Library/Frameworks/Mono.framework/Versions/Current/bin/:${PATH}' >> ~/.zshrc

のような感じでパスを通した方が良さそう。
(MonoはBrewだとうまくいかないみたいなので手動インストールした)

AppleID

ついでにメモ。
GmailのアドレスでAppleIDを作成する方法

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?