写真のファイル名をEXIFの撮影日時に変更する

写真のファイル名をEXIFの撮影日時に変更するスクリプトです。
オリジナルの日付が記録された写真を選択して、スクリプトエディタ上または、スクリプトメニューから実行できます。
このように変わります。 xxxxxxxxxx.jpeg --> 2022-05-23 06.00.37.jpeg
写真のファイル名をEXIFの撮影日時に変更する.scptd

tell application "Finder"
set aSel to the selection as alias list
repeat with i in aSel
set j to contents of i
set aProp to properties of j
if class of aProp is not folder then
set anExt to name extension of j
set aName to name of j
try
set exiftool to ((path to me) as string) & "Contents:resources:exiftool:"
set dateAndtime to do shell script (quoted form of POSIX path of exiftool) & "exiftool -S -T -DateTimeOriginal " & quoted form of POSIX path of j
-----
set curDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set aDate to item 1 of (text items of dateAndtime)
set AppleScript's text item delimiters to curDelim
set aDate to replaceText(aDate, ":", "-") of me
-----

-----
set curDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set aTime to item 2 of (text items of dateAndtime)
set AppleScript's text item delimiters to curDelim
set aTime to replaceText(aTime, ":", ".") of me
-----
set newDateAndtime to aDate & " " & aTime
set name of j to newDateAndtime & "." & anExt
on error msg
beep
display dialog "エラー" with title aName with icon 2 buttons {"OK"}
end try
end if
end repeat
end tell

--任意のデータから特定の文字列を置換
on replaceText(origData, origText, repText)
set curDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to {origText}
set origData to text items of origData
set AppleScript's text item delimiters to {repText}
set origData to origData as text
set AppleScript's text item delimiters to curDelim
return origData
end replaceText

更新履歴

inserted by FC2 system