Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Enhanced version' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Enhanced version
Authored by: Tschuess on Oct 02, '08 01:45:36PM
Thank you for this nice Script, this is a slightly enhanced Version with: Code cleanup; not dot at the end of filename; no extension in the middle of filename; clear TimeStamp like "2008-10-02 21_37_25"

(*
Create timestamped duplicates
duplicates any files selected in the Finder, and adds the date and time to their names. This makes it easy to go back by looking at the date and time embedded in the filename.

  Submitted by PizzaCake  Sep 29 2008 at 7:30AM PDT 
 enhanced by B.Bippus 2008-10-02: Code cleanup; not dot at the end of filename; no extension in the middle of filename; clear TimeStamp like "2008-10-02 21_37_25"
 *)
on open
	run -- Now you can either select the files or drop them on the app  
end open

tell application "Finder"
	set theselection to selection
	repeat with i from 1 to (count theselection)
		set aFileOrFolder to item i of theselection
		
		set ParentFolder to folder of (aFileOrFolder) as alias
		
		set theFileName_with_extension to name of (aFileOrFolder) as text
		set theFileExtension to my getFileExtension(theFileName_with_extension)
		set theFileName to my StripFileExtension(theFileName_with_extension)
		set thedate to my TimeStamp("")
		set theNewName to theFileName & " " & thedate & theFileExtension as text
		
		set theDuplicate to duplicate (aFileOrFolder) to ParentFolder replacing no
		set theDuplicateAlias to theDuplicate as alias
		set name of theDuplicateAlias to theNewName
		
	end repeat
	select (aFileOrFolder) -- select original item in finder 
end tell


--* Version 21.08.2007 (02.10.2008)
on TimeStamp(aTimeDate) --> returns: "2007-08-12"
	-- aTimeDate: full AS date like:  "Sonntag, 12. August 2007 13:46:43 Uhr"
	-- or aTimeDate = "" for current date time
	if aTimeDate is "" then
		copy (current date) to aTimeDate
	end if
	set totalSeconds to (time of (aTimeDate))
	set theHour to totalSeconds div 3600
	set theMinutes to (totalSeconds mod 3600) div 60
	set theSeconds to totalSeconds mod 60
	copy (theHour as string) & "_" & theMinutes & "_" & theSeconds to aTime
	
	copy short date string of (aTimeDate) to aDate
	
	set as_txt_del to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "."
	copy text item 3 of aDate & "-" & text item 2 of aDate & "-" & text item 1 of aDate to thedateStamp
	set AppleScript's text item delimiters to as_txt_del
	
	--return thedateStamp
	copy thedateStamp & " " & aTime to aTimeStamp
	return aTimeStamp
end TimeStamp

on StripFileExtension(t_fileName) -- 02.10.2008/ 29.08.2007
	set AppleScript's text item delimiters to ""
	set t_fileName to "_" & t_fileName -- ".fh8"  empty filename
	if "." is in t_fileName then
		set myOffSet to (offset of "." in (reverse of characters of t_fileName as string))
		set t_fileName to characters 1 thru -(myOffSet + 1) of t_fileName as text
	end if
	if length of t_fileName > 1 then -- empty filename
		set t_fileName to characters 2 thru -1 of t_fileName as string
	else
		set t_fileName to ""
	end if
	return t_fileName
end StripFileExtension

on getFileExtension(t_fileName) -- 02.10.2008/ 29.08.2007
	set AppleScript's text item delimiters to ""
	set t_extension to "_" & t_fileName -- eg  empty filename = ".txt" 
	if "." is in t_fileName then
		set myOffSet to offset of "." in t_fileName as string
		set myOffSet to (offset of "." in (reverse of characters of t_fileName as string))
		if (myOffSet > 1) then
			set t_extension to characters (-1 * (myOffSet - 1)) thru -1 of t_fileName as text
		else
			set t_extension to ""
		end if
	else
		set t_extension to ""
	end if
	if length of t_extension = 0 then --  filename  empty
		set t_extension to ""
	end if
	return t_extension
end getFileExtension
Paste into Script Editor, and save as application. Select some file/s in the Finder, then run the saved AppleScript.



[ Reply to This | # ]