指定の画像からEXIF情報を取得し、撮影日付(DateTimeOriginal)を取得するAppleScriptです。
Image Eventsで取得するよりも、BridgePlusで取得するほうが高速だったので差し替えてみました。
AppleScript名:指定の画像からEXIFの撮影日付(DateTimeOriginal)を取得 v2 |
— Created 2014-12-14 by Takaaki Naganoya — 2014 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use BPlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html property NSString : a reference to current application’s NSString property NSLocale : a reference to current application’s NSLocale property SMSForder : a reference to current application’s SMSForder property NSDateFormatter : a reference to current application’s NSDateFormatter set aTargFile to choose file of type {"public.image"} set exifRes to readExifDateTimeOriginal(aTargFile) of me –指定ファイルからのExifデータを取得し撮影日付を取得する on readExifDateTimeOriginal(aTargFileAlias) set theMetadata to readMetadataFrom(aTargFileAlias) of me set keysList to theMetadata’s allKeys() if "{Exif}" is not in (keysList as list) then return false set exifDate to theMetadata’s valueForKeyPath:"{Exif}.DateTimeOriginal" if exifDate = missing value then return false set fullDate to dateFromStringWithDateFormat(exifDate, "yyyy:MM:dd HH:mm:ss") of me return fullDate end readExifDateTimeOriginal –指定ファイルからのメタデータ読み込み on readMetadataFrom(imageFile) load framework set {theRecord, theError} to SMSForder’s metadataFromImage:imageFile |error|:(reference) if theRecord = missing value then — there was a problem, so extract the error description error (theError’s localizedDescription() as text) — number (theError’s code()) else return theRecord end if end readMetadataFrom –日付文字列を形式指定しつつdate objectに変換 on dateFromStringWithDateFormat(dateString, dateFormat) set dStr to NSString’s stringWithString:dateString set dateFormatStr to NSString’s stringWithString:dateFormat set aDateFormatter to NSDateFormatter’s alloc()’s init() aDateFormatter’s setDateFormat:dateFormatStr aDateFormatter’s setLocale:(NSLocale’s alloc()’s initWithLocaleIdentifier:"en_US_POSIX") set aDestDate to (aDateFormatter’s dateFromString:dStr) return aDestDate as list of string or string end dateFromStringWithDateFormat |
More from my site
(Visited 201 times, 1 visits today)