(覚書)ParallelsのWindowsのバックアップファイルネームを日時に変更するApple Script

 

ParallelsWindowsをバックアップのために別のDiskにコピーしているのですが、コピー先のファイルネームをコピーした日時に変更しようと作ったApple Scriptの覚書です。

このスクリプトだと、BackUpDisk内のParallels Backupフォルダ内のWindows.pvmという名前のファイル名を、「今の時間.pvm」というファイル名(20190219-121212.pvmなど)に変更します。

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
tell application "Finder"
activate
set current_date to current date
set val_year to year of current_date
set val_month to month of current_date as number
set val_day to day of current_date
set val_hours to hours of (current date)
set val_minutes to minutes of (current date)
set val_seconds to seconds of (current date)

if val_month < 10 then
set val_month to "0" & val_month as string
end if

if val_day < 10 then
set val_day to "0" & val_day as string
end if

if val_hours < 10 then
set val_hours to "0" & val_hours as string
end if

if val_minutes < 10 then
set val_minutes to "0" & val_minutes as string
end if

if val_seconds < 10 then
set val_seconds to "0" & val_seconds as string
end if

set date_time_string to val_year & val_month & val_day & "-" & val_hours & val_minutes & val_seconds as text

set name of document file "Windows.pvm" of folder "Parallels Backup" of disk "BackUpDisk" to date_time_string & ".pvm"

end tell
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー