【AppleScript】Finder上で複数個選択し、ファイルをそれぞれ同じ階層に文字列を追加して複製するスクリプト
お世話になります。
Finder上でフォルダが複数あり、その中にファイルがそれぞれ入っているとします。
ファイルを選択し、それぞれのファイルと同じ階層に文字列を追加し複製したいです。
tell application "Finder"
activate
display dialog "追加する文字を入力" default answer "-001" -- 追加する文字を指定
set NewName to text returned of the result as Unicode text -- 変更後のファイル名をNewNameに格納
set sel to get selection --選択ファイル
set ObjInfo to info for sel as alias --選択ファイルの情報を取得
set FileName to name of ObjInfo as Unicode text --選択ファイルのファイル名をFileNameに格納
set FileNameChrList to every character of FileName --ファイル名の文字を分割
set tmpFileName to reverse of FileNameChrList as Unicode text -- ファイル名テキストの順番を逆にする
set c to offset of "." in tmpFileName -- ファイル名の"."がテキストの先頭から何番目にあるか
set preFix to reverse of (characters 1 thru c of tmpFileName) -- "."から最後までの文字を取り出す("."含めた拡張子)
set retFileName to reverse of (characters (c + 1) thru (length of tmpFileName) of tmpFileName) -- "."から最初までの文字を取り出す("."の前のファイル名)
set duplicatedFile to duplicate sel --選択ファイルを複製
set name of duplicatedFile to (retFileName as Unicode text) & (NewName as Unicode text) & (preFix as Unicode text) -- 複製したファイルを変更
end tell
一つのファイルだけなら上記のスクリプトで一応出来ました。
これを複数選択して、それぞれのファイルと同階層にやりたいです。
どうやったら出来るのか教えていただきたいです。
macOS Catalina バージョン10.15.7の環境になります。
iMac Pro