Mac の便利コマンド

タッチできる目次

DNSキャッシュクリア

sudo killall -HUP mDNSResponder

DS_Store 一括削除

find . -name '.DS_Store' -type f -ls -delete

DS_Store を作成しない

defaults write com.apple.desktopservices DSDontWriteNetworkStores True

隠しファイルを表示

3つのキーを同時押し

[command] + [shift] + [.(ドット)]

コマンドで設定する場合

表示する

defaults write com.apple.finder AppleShowAllFiles TRUE

非表示

defaults write com.apple.finder AppleShowAllFiles FALSE

Finder を再起動して反映

killall Finder

Finder に終了を追加

defaults write com.apple.Finder QuitMenuItem -boolean true

# Finder 再起動
Killall Finder 

もとに戻す

defaults delete com.apple.Finder QuitMenuItem

cdf でカレントディレクトリへ移動

https://stackoverflow.com/questions/18456682/mac-terminal-change-directory-to-current-front-finder-window

Macで開いているウィンドウへ移動するコマンド

vim ~/.zshrc

下部に追加する

cdf() {
  target=`osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'`
  if [ "$target" != "" ]; then
    cd "$target"; pwd
  else
    echo 'No Finder window found' >&2
  fi
}

alias f='open .'

設定を反映

source ~/.zshrc

ターミナルで 「cdf」 を入力すると開いているウィンドウのカレントディレクトリが開きます。

Chrome の SSLエラーを回避

https://qiita.com/DisneyAladdin/items/051eeef71cece244bd11

開発などでSSLエラーが出てサイトを開けない場合

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --ignore-certificate-errors --ignore-urlfetcher-cert-requests &> /dev/null

または以下で直接Chromeを起動する

open -a Google\ Chrome --args --ignore-certificate-errors --ignore-urlfetcher-cert-requests && exit