Open1
MacでZipファイルをダウンロード時に自動で解凍する
macOS Automator で ZIP ファイル自動解凍設定
最終的なスクリプト
for f in "$@"
do
if [[ "$f" == *.zip ]]; then
# ZIPファイル名から拡張子を除いた名前を取得
basename=$(basename "$f" .zip)
# ZIPファイルがあるディレクトリを取得
dir=$(dirname "$f")
# 展開先フォルダのパスを作成
extract_dir="$dir/$basename"
# フォルダを作成して展開
mkdir -p "$extract_dir"
unzip -o "$f" -d "$extract_dir"
fi
done
設定手順
1. Automator でフォルダアクションを作成
- Automator を起動
- 「新規書類」→「Folder Action」を選択
- 右上のプルダウンから「Downloads」フォルダを選択
2. Filter Finder Items を設定
- 左側から「Filter Finder Items」をワークフローにドラッグ
- 以下の条件を設定:
- Find files where:
All
- of the following are true:
-
File extension
is
zip
- Find files where:
3. Run Shell Script を追加
- 左側の「Utilities」から「Run Shell Script」をワークフローにドラッグ
- 以下の設定を行う:
-
Shell:
/bin/bash
-
Pass input:
as arguments
- スクリプト: 上記の最終的なスクリプトをコピー&ペースト
-
Shell:
4. 保存
-
Command + S
で保存 - 名前を付ける(例:「Auto Unzip to Folder」)
動作内容
- Downloads フォルダに ZIP ファイルが追加されると自動的に動作
- ZIP ファイルと同名のフォルダを作成して、その中に解凍
- 元の ZIP ファイルは削除されない
例
-
sample.zip
→Downloads/sample/
フォルダに解凍 -
project.zip
→Downloads/project/
フォルダに解凍