최근 이미지 파일을 [WebP 포멧](https://developers.google.com/speed/webp?hl=ko)으로 변환할 일이 많아졌다. 아쉽게도 애플 환경은 HEIC 포멧을 밀고 있기 때문에 공식적으로 WebP 변환 방법은 없다.
가장 간단한 방식은 [`cwebp`](https://developers.google.com/speed/webp/docs/cwebp?hl=ko) 커맨드를 활용하는 것이다. 커맨드 실행은 접근성이 낮으니 macOS 파인더에서 선택한 파일을 즉시 변환해주는 스크립트를 작성하고, 이를 [Raycast](https://www.raycast.com/) 스크립트 실행에 연동하였다.
## convert-to-webp-file.sh
```bash
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Convert to WebP file
# @raycast.mode fullOutput
# Optional parameters:
# @raycast.icon 🖼️
# Documentation:
# @raycast.author chorr
# @raycast.authorURL https://raycast.com/chorr
# Check if cwebp is installed
if ! command -v cwebp &> /dev/null; then
echo "cwebp could not be found. Please install it using 'brew install webp'."
exit 1
fi
# AppleScript to get the selected files in Finder
selected_files=$(osascript <<EOD
tell application "Finder"
set theSelection to selection
if (count of theSelection) is 0 then
return "no selection"
else
set selectedPaths to ""
repeat with anItem in theSelection
set selectedPaths to selectedPaths & POSIX path of (anItem as alias) & linefeed
end repeat
return selectedPaths
end if
end tell
EOD
)
# Check if no files were selected
if [ "$selected_files" = "no selection" ]; then
echo "No files selected."
exit 1
fi
# Convert the newline-separated list of selected files into an array
IFS=