# [メタ情報] # 識別子: dropboxリンクに一致するフルパス検索_exe # システム名: dropboxリンクに一致するフルパス検索 # 技術種別: Misc # 機能名: Misc # 使用言語: AppleScript ShellScript # 状態: 実行用 # [/メタ情報] dropboxリンクに一致するフルパス検索.app -- ▼ 対象フォルダ(サブフォルダも含めて検索) set folder1 to "/Volumes/NO3_SSD/Dropbox/dropbox_1/mmedia" set folder2 to "/Volumes/NO3_SSD/Dropbox/dropbox_1/pmedia" repeat -- ▼ Dropboxリンクの入力 display dialog "Dropboxの共有リンクを入力してください(キャンセルで終了):" default answer "" buttons {"キャンセル", "OK"} default button "OK" set dropboxURL to text returned of result -- ▼ Dropboxリンクからファイル名を抽出 set dropboxStyleName to do shell script " echo " & quoted form of dropboxURL & " | sed -E 's|.*/([^/?]+).*|\\1|' | tr -d '\\r\\n '" -- ▼ ファイル名確認ダイアログを表示 display dialog "ファイル名から日本語を除いた部分が「" & dropboxStyleName & "」となるフルパスを検索します。" buttons {"OK"} default button "OK" -- ▼ Shellスクリプトで一致ファイルを検索 set shellScript to " find " & quoted form of folder1 & " " & quoted form of folder2 & " -type f | while read f; do base=$(basename \"$f\") converted=$(echo \"$base\" | sed -E ' s/[一-龯ぁ-んァ-ンー々〆〤]+/-/g; s/-+/-/g; s/-([.][^.]+)$/\\1/; s/^-(.*)$/\\1/') if [ \"$converted\" = " & quoted form of dropboxStyleName & " ]; then echo \"$f\" fi done" try set matchResult to do shell script shellScript on error set matchResult to "" end try if matchResult is not "" then set resultList to paragraphs of matchResult set the clipboard to matchResult if (count of resultList) > 1 then display dialog "一致するファイルパスが複数存在します。" buttons {"OK"} default button "OK" end if -- ▼ 結果表示と次の選択 set userChoice to button returned of (display dialog "一致したファイルパス:" & return & return & matchResult buttons {"処理を続ける", "終了"} default button "処理を続ける") if userChoice is "終了" then exit repeat else set userChoice to button returned of (display dialog "一致するファイルは見つかりませんでした。" buttons {"処理を続ける", "終了"} default button "処理を続ける") if userChoice is "終了" then exit repeat end if end repeat