[macOS] よく使うdefaults writeコマンド

2 min read
hiroweb developer

概要

macOS には、コマンドラインからシステムの設定を変更できる defaults writeコマンドがある。個人的に使っているものをピックアップし記載する。

デスクトップのアイコンを制御する

macOS のデスクトップ上に表示されるアイコンの表示・非表示を切り替えることができる。

# 非表示にする
defaults write com.apple.finder "CreateDesktop" -bool "false" && killall Finder

# 表示する
defaults write com.apple.finder "CreateDesktop" -bool "true" && killall Finder

ここで、killall Finderは Finder を再起動して、変更をすぐに反映させるためのコマンドである。

スクリーンショットを制御する

スクリーンショットに影をつけるか、保存場所を変更する、画像形式を指定するなどの操作が可能。

スクリーンショットに影をつけるかどうかを設定する。

# 影を追加する
defaults write com.apple.screencapture "disable-shadow" -bool "false"

# 影を削除する
defaults write com.apple.screencapture "disable-shadow" -bool "true"

保存場所を変更する

スクリーンショットの保存場所を変更するには、以下。下記の例では、スクリーンショットの保存場所を~/Pictures/Screenshotsに設定する例である。

defaults write com.apple.screencapture location ~/Pictures/Screenshots

画像形式を変更する

スクリーンショットの画像形式は以下のコマンドで変更できる。対応している拡張子は、png, jpg, pdf, psd, gif, tga, tiff, bmpである。

defaults write com.apple.screencapture "type" -string "png"