[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(DTPtechNote:399) rename



ちょっとぬるい目系でつ。
ファイルの作成日の日付をつけます。for OS X
デジカメの整理なんかにどうぞ。

on open of theFiles
	tell application "Finder"
		--activate
		repeat with i in theFiles
			set my_date to creation date of contents of i
			set y to (year of my_date) as Unicode text
			set m to my zero2(my monthNumStr((month of my_date)))
			set d to my zero2(day of my_date)
			set h to my sec2hour(time of my_date)
			set old_name to name of contents of i
			if old_name contains ("." as Unicode text) then
				set ext to "." & last item of my as_split("." as Unicode text, old_name)
			else
				set ext to ""
			end if
			
			set file_name to (y & "." & m & ". " & d & "_" & h & ext) as Unicode text
			set name of file i to (file_name as Unicode text)
		end repeat
	end tell
end open

to monthNumStr(theMonth)
	set monList to {January, February, March, April, May, June, July, August, September, October, November, December}
	repeat with i from 1 to 12
		if item i of monList is theMonth then exit repeat
	end repeat
	return i
end monthNumStr

to sec2hour(sec)
	set m to sec div 60
	set s to my zero2(sec mod 60)
	if m > 60 then
		set h to my zero2(sec div 3600)
		set m to my zero2((sec mod 3600) div 60)
	else
		set h to "00"
	end if
	return h & "." & m & "." & s
end sec2hour

to zero2(n)
	if n < 10 then
		return "0" & n
	else
		return n as text
	end if
end zero2

to as_split(thedelimit, theText)
	set oldDelim to AppleScript's text item delimiters
	set AppleScript's text item delimiters to thedelimit
	set tmpList to every text item of theText
	set AppleScript's text item delimiters to oldDelim
	return tmpList
end as_split