- Launch "Automator", then "New" > "Quick Action"
- "Workflow receives current
files or foldersinFinder" - "Pass input:
as arguments" - Paste the content of
convert_to_mp4.shinto the shell vie - Save the workflow
| #!/bin/bash | |
| # Commands | |
| FFMPEG="/opt/homebrew/bin/ffmpeg" | |
| NOTIFY="/opt/homebrew/bin/terminal-notifier" | |
| # Make sure PATH includes Homebrew | |
| export PATH="/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin" | |
| # Ask user for scale | |
| SCALE_INPUT=$(osascript -e 'display dialog "Enter scale (e.g. 1280:-1)\nLeave blank for original size:" default answer ""' -e 'text returned of result') | |
| # Trim spaces (just in case) | |
| SCALE_INPUT=$(echo "$SCALE_INPUT" | tr -d '[:space:]') | |
| # Automatically fix odd-dimension issue: replace ":-1" with ":-2" | |
| SAFE_SCALE=$(echo "$SCALE_INPUT" | sed 's/:-1$/:-2/') | |
| last_out="" | |
| # Process each selected file | |
| for f in "$@" | |
| do | |
| dir=$(dirname "$f") | |
| base=$(basename "$f") | |
| name="${base%.*}" | |
| if [ -z "$SAFE_SCALE" ]; then | |
| # Original size | |
| out="${dir}/${name}.mp4" | |
| "$FFMPEG" -i "$f" \ | |
| -vcodec libx264 -pix_fmt yuv420p -crf 23 -preset medium \ | |
| -acodec aac -movflags +faststart \ | |
| "$out" 2> ~/Desktop/ffmpeg_error.log | |
| else | |
| # Custom scale | |
| out="${dir}/${name}_$(echo "$SAFE_SCALE" | tr -d ":").mp4" | |
| "$FFMPEG" -i "$f" \ | |
| -vf "scale=${SAFE_SCALE}" \ | |
| -vcodec libx264 -pix_fmt yuv420p -crf 23 -preset medium \ | |
| -acodec aac -movflags +faststart \ | |
| "$out" 2> ~/Desktop/ffmpeg_error.log | |
| fi | |
| last_out="$out" | |
| done | |
| # Notify user when finished | |
| "$NOTIFY" \ | |
| -title "ffmpeg" \ | |
| -message "Conversion completed." \ | |
| -actions "Show" \ | |
| -execute "open -R \"$last_out\"" |