Last active
October 21, 2024 01:07
-
-
Save yujikuroki/07ea73871a6e70e26667232882047416 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/zsh | |
| # Automatorで新規ファイルを作成し「クイックアクション」を選択する | |
| # 「ワークフローが受け取る現在の項目」で「ファイルまたはフォルダ」を選択する | |
| # 検索対象で「Finder.app」を選択する | |
| # 画面左「アクション」で「シェル」と検索し「シェルスクリプトを実行」をダブルクリックする | |
| # 「シェルスクリプトを実行」のテキスト編集フォーム右上の「Pass input」を「as arguments」にする | |
| # 「シェルスクリプトを実行」のテキスト編集フォームに本スクリプトをペーストする | |
| display_alert() { | |
| osascript -e "display alert \"$1\"" | |
| } | |
| add_bom_to_csv() { | |
| local file="$1" | |
| local tmpfile=$(mktemp) | |
| printf '\xEF\xBB\xBF' > "$tmpfile" | |
| cat "$file" >> "$tmpfile" | |
| mv "$tmpfile" "$file" | |
| } | |
| if [[ $# -ne 1 ]]; then | |
| echo "エラー: 1つのファイルのみを選択してください。" >&2 | |
| exit 1 | |
| fi | |
| file="$1" | |
| ext="${file:e:l}" | |
| if [[ "$ext" != "csv" ]]; then | |
| echo "${file:t} はCSVファイルではありません。処理を中止します。" >&2 | |
| exit 1 | |
| fi | |
| add_bom_to_csv "$file" | |
| display_alert "${file:t} にBOMを付与しました。" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment