2016-09-12T18:16:01+09:00

ファイルの制作日と修正日をコピーする AppleScript

ファイルの作成日と修正日を別のファイルにコピーする AppleScript のサンプルです。

ファイルの同定や発見にいつ頃のファイルか?というのは重要な情報だと思います。あの内容のファイルはいつ頃だったけ〜という、うろ覚えの感覚を頼りしばしば古いファイルを探すことがあります。

ファイルの容量を圧縮するために画像フォーマットの変換や圧縮をした時に、元のファイルの時間情報が変換/圧縮後のファイルにあると、そんな時に便利かなと思って、画像変換のスクリプト(未公開)や ZipArchiver に使おうと思っています。

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

on run
set src_path to "/path/to/source.BMP"
set dest_path to "/path/to/dest.png"
copy_timestamp(src_path, dest_path)
end run

on copy_timestamp(src_path, dest_path)
tell current application's NSFileManager's defaultManager()
set attr to its attributesOfItemAtPath:src_path |error|:(missing value)
set a_dict to {NSFileCreationDate:attr's objectForKey:"NSFileCreationDate", NSFileModificationDate:attr's objectForKey:"NSFileModificationDate"}
its setAttributes:a_dict ofItemAtPath:dest_path |error|:(missing value)
end tell
end copy_timestamp