環境
やりたいこと
MacOSでファイルの拡張子(例:.txtや.md)を特定のアプリケーション(例:CotEditor)に関連付けるのをコマンドラインで一括設定したい。 FinderのGUIから行うのが一般的だが、普通にめんどい。
でいいのがないか探していたらちょうど専用のライブラリがあった。てか標準コマンドで用意しとけよ
インストール
brew install duti
手順
まずは開きたいアプリのアプリ識別子を知る必要がある。例えばCotEditorの場合は
osascript -e 'id of app "CotEditor"' # 出力例:com.coteditor.CotEditor
あとは関連付けを変えたい拡張子の数だけコマンドを実行する
duti -s com.coteditor.CotEditor .txt all duti -s com.coteditor.CotEditor .md all
動画系をすべてIINAにするコマンド
extensions=("avi" "flv" "mkv" "mov" "mp4" "mpeg" "mpg" "ogv" "rmvb" "webm" "wmv" "hevc") for ext in "${extensions[@]}"; do duti -s com.colliderli.iina $ext all done