2つのファイルの作成日時を合わせるAppleScript

OSX 10.9 MavericksのQuickTime Player 10.3では、未対応のコーデックは変換してから再生する。

以前はperianを入れると普通に再生出来たので、つまりQuickTimeとその古いコーデックはサポート打ち切りですね。

QuickTimeの終焉とともに、古いQuickTimeの動画ファイルをh.264あたりに変換して保存しようと思った。だが、変換後に保存するとファイル作成日時が現在の日時になってしまう。

mov形式の場合、タグ情報(ムービーのプロパティ)に作成者や作成日時が入っていることもあるが、無い場合も多い。

よって、変換前後の2つのファイルをドロップして、作成日時の古い方へ同期を取るAppleScriptを作成してみた。

 

使い方

ドロップレットで書き出して、2つのファイルを一緒にドロップするだけ。

 

SyncCreateDate.scpt
(*
2つのファイル作成日付を比較して、古い方に合わせる。
*)


on
open theList
    
toControl(theList)
end
open

on
run
    
choose file with prompt "ファイルを2つ選んでください" multiple selections allowed yes without invisibles
    if
class of result is list then
        
toControl(result)
    else
        
toControl({result})
    end if
end
run

on
adding folder items to theFolder after receiving theList
    
toControl(theList)
end
adding folder items to

property
ARGV : null

on
toControl(theList)
    
    set
ARGV to null
    
    if (
count of theList) is not 2 then
        
finishNotification(no)
        return
    end if
    
    set
ARGV to theList
    
    
--作成日付の比較
    set
theSortedList to sortOnCreationData(theList) of me
    
    
--作成日付の変更
    
setFileDate(second item of theSortedList, first item of theSortedList)
    
    
finishNotification(yes)
end
toControl

(*
作成日付の比較
return:old,new のリストで返す
*)

on
sortOnCreationData(theList)
    
    set
sortedList to theList
    
    set
firstDate to creation date of (info for first item of theList)
    set
secondeDate to creation date of (info for second item of theList)
    
    if
firstDate > secondeDate then
        set
sortedList to reverse of theList -- 逆順に入れ替え
    end if
    
    return
sortedList
end
sortOnCreationData






(*処理終了通知*)
on
finishNotification(normalEnd)
    
--処理終了の通知
    if
normalEnd is yes then
        set
msg to name of (info for first item of ARGV) & return & name of (info for second item of ARGV) as string
        
display notification msg with title "Normal End" sound name "beep"
    else
        if
ARGV is null then
            set
msg to ""
        else
            set
msg to name of (info for first item of ARGV) & return & name of (info for second item of ARGV) as string
        end if
        
display notification msg with title "Abnormal End" sound name "beep"
        
    end if
    
delay 1
end
finishNotification

(*ファイル日付の設定*)
on
setFileDate(theFile, theSourceFile)
    set
theCommand to "x=`/Developer/Tools/GetFileInfo -d " & quoted form of POSIX path of theSourceFile & "` && " & "/Developer/Tools/SetFile -d \"$x\" " & quoted form of POSIX path of theFile
    
do shell script theCommand
end
setFileDate

 

動作環境

OSX 10.9以降。でも通知処理を除けば10.4くらいでも動きそう。

Xcode(/Developer/Tools/)

 

実行環境

QuickTime Player 10.3/Apple/iMac10,1/OSX 10.9.2