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

An AppleScript droplet to change the creation date System
When scanning old photos -- say from the 1980s -- logically the date of the scanning becomes the files' creation date. The problem is that afterwards, when you list the 1980s pictures alongside other pictures (in iPhoto, the Finder, or wherever), the scanned pictures are going to be out of real-time chronological order. That is, the 1980s pictures should come before any pictures taken with your digital camera.

To change the creation date, I wrote this small AppleScript droplet application. Copy and paste the text into a new script in Script Editor, and then save it as an application.

With the script in place, I take the 1980s picture files that I just scanned, and drop the file(s) or the folder onto the application. The script then asks me for the new creation date (ie: 1/1/1985), and then it does its work. There are shareware solutions out there that do this, but the ones I found were a tad overbuilt, or not as quick to use. I wanted it to be fast-to-use and super simple. My script could be modified to make date entry easier, but for me, this is really all I need.

[robg adds: When I tested this, it worked if I dropped a file (or multiple files) onto the applet. If I dropped a folder of files, however, nothing seemed to happen.]
    •    
  • Currently 3.35 / 5
  You rated: 5 / 5 (17 votes cast)
 
[72,961 views]  

An AppleScript droplet to change the creation date | 29 comments | Create New Account
Click here to return to the 'An AppleScript droplet to change the creation date' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
free-form date entry and folder
Authored by: Krioni on Jul 07, '06 02:16:25PM
Here's another version of this script that allows you to enter the date in mostly free-form (AppleScript changes it to the required date format). Paste this into Script Editor and save as Application.

-- ChangeCreationDate
-- version 1.0, Daniel A. Shockley (http://www.danshockley.com)
--    idea suggested by spacericker9k on macosxhints.com, at:
--        http://www.macosxhints.com/article.php?story=20060703160750583

on run
	
	-- some coding formatted to keep the individual lines shorter
	
	set dialogMsg to "Choose a folder of files to change, or file(s)?"
	set buttonChoices to {"Cancel", "Folder", "Files"}
	set openChoice to button returned of (display dialog dialogMsg buttons buttonChoices default button "Files")
	
	if openChoice is "Files" then
		set chooseFileDialog to "Choose the file(s) you want to change:"
		set fileList to choose file with prompt chooseFileDialog with multiple selections allowed
		
	else if openChoice is "Folder" then
		set oneFolder to choose folder with prompt "Choose the folder whose files you want to change:"
		tell application "Finder"
			set fileList to (files of oneFolder) as alias list
		end tell
		
	end if
	
	changeCreationDate(fileList)
	
end run


on open someItems
	-- someItems could be files or folders - will only process FILES
	
	changeCreationDate(someItems)
	
end open


on changeCreationDate(fileList)
	-- version 1.0, Daniel A. Shockley (http://www.danshockley.com)
	
	-- for now, just handle files, not folders
	set dialogMsg to "Please choose a new creation date for the file(s)."
	set newCreationDate to date (text returned of (display dialog dialogMsg default answer ""))
	
	set creationDateString to year of newCreationDate as string
	set creationDateString to creationDateString & text -2 thru -1 of ("0" & getMonthNum(newCreationDate) as string)
	set creationDateString to creationDateString & text -2 thru -1 of ("0" & day of newCreationDate as string)
	set creationDateString to creationDateString & text -2 thru -1 of ("0" & hours of newCreationDate as string)
	set creationDateString to creationDateString & text -2 thru -1 of ("0" & minutes of newCreationDate as string)
	set creationDateString to creationDateString & "." & text -2 thru -1 of ("0" & seconds of newCreationDate as string)
	
	repeat with oneItem in fileList
		
		if folder of (info for oneItem without size) is false then
			
			set shellCommand to "touch -t " & creationDateString & " " & quoted form of POSIX path of oneItem
			
			set logMsg to ("Changed creation date of file '" & oneItem as string) & "' to " & newCreationDate as string
			logConsole("changeCreationDate", logMsg)
			
			do shell script shellCommand
			
		end if
		
	end repeat
	
	
end changeCreationDate



on getMonthNum(theDate)
	-- French Vanilla, by Emmanuel Lévy
	--set theDate to the current date --or any other date
	copy theDate to b
	set the month of b to January
	set monthNum to (1 + (theDate - b + 1314864) div 2629728)
	return monthNum
end getMonthNum



on logConsole(processName, consoleMsg)
	-- version 1.5 - Daniel A. Shockley, http://www.danshockley.com
	-- 1.5- uses standard date-stamp format	
	set timeStamp to do shell script "date +\"%Y-%m-%d %H:%M:%S\""
	set hostName to do shell script "hostname -s" & space
	set logMsg to (return & timeStamp & space & hostName & space & processName & ":" & space & consoleMsg)
	set shellCommand to "echo" & space & quoted form of logMsg & " >> /dev/console"
	
	do shell script shellCommand
	
end logConsole

---
--
http://www.danshockley.com

[ Reply to This | # ]

follow-up - can choose folder, file, or drag-and-drop
Authored by: Krioni on Jul 07, '06 02:23:23PM

Quick follow-up note: this script allows you to run it and then choose a folder, files, or use drag-and-drop.

---
--
http://www.danshockley.com



[ Reply to This | # ]
Correction: the previous script sometimes fails
Authored by: Krioni on Aug 11, '09 02:47:32PM
The script above does not always work. Apparently it fails to set the creation date in some cases (Google for more). There are two alternatives, since the built-in 'touch' tool is not always reliable for the creation date: using the SetFile binary that comes with Apple's Mac OS X Developer Tools, or using a separate binary tool created by HAMSoft Engineering, found at http://www.hamsoftengineering.com/codeSharing/ChangeFileDates/ChangeFileDates.html

I'll post code in this comment for using the HAMSoft binary, and a separate comment showing how to use SetFile.


on run
	
	-- uses the binary tool ChangeFileDates by HAMSoft Engineering, 
	-- found at http://www.hamsoftengineering.com/codeSharing/ChangeFileDates/ChangeFileDates.html
	
	-- this will change the creation and modification dates of a chosen file
	-- put the command-line executable binary tool in a ChangeFileDates sub-folder 
	-- of the Application Support folder inside your user Library folder
	-- OR, change the path below
	
	set changeFileDatesPath to (path to application support folder from user domain as text) & ¬
		"ChangeFileDates:ChangeFileDates"
	
	set creationDate to (current date) - 3 * days -- 3 days ago from now
	set modificationDate to (current date) - 1 * days -- 1 day ago from now
	
	set modificationDateFormatted to dateUnixFormat(modificationDate, "%m/%d/%Y %H:%M:%S")
	set creationDateFormatted to dateUnixFormat(creationDate, "%m/%d/%Y %H:%M:%S")
	
	set aFile to choose file without invisibles
	
	try
		set shellCommand to quoted form of POSIX path of changeFileDatesPath & ¬
			" -cDate " & quoted form of creationDateFormatted & " -mDate " & ¬
			quoted form of modificationDateFormatted & " -file " & ¬
			quoted form of POSIX path of aFile
		do shell script shellCommand
	on error theError number errorNumber
		display dialog "There was an error:" & return & theError & return & return & ¬
			"Error Number: " & errorNumber as text buttons {"OK"} default button 1 with icon stop
	end try
	
end run

on dateUnixFormat(theDate, unixFormatString)
	-- version 1.2, Daniel A. Shockley, http://www.danshockley.com
	-- includes code from Paul Berkowitz and Nigel Garvey on applescript-users mailing list
	-- updates suggested by Jonn8 on macscripter.net BBS
	
	-- dateUnixFormat DID NOT SEEM TO WORK with new Daylight Savings Time ! ! ! !
	-- BUT, subtracting an hour seems to fix it.
	
	-- run 'man strftime' in a shell to read the formatting options
	-- basics are: %d = dd, %m = mm, %Y = yyyy, %F = %Y-%m-%d, %M = MM (minutes), %H = HH (military), %S = SS
	
	try
		-- get the starting Unix date as an AppleScript date
		set theEpoch to (date (do shell script "date -r 0 '+%a %b %e %Y %H:%M:%S'"))
		set unixSecs to theDate - (theEpoch)
		
		set unixSecs to unixSecs - 1 * hours -- HACK to get around bug, seemingly caused by new DST
		
		set unixSecs to my NumberToString(unixSecs)
		
		set theDate to do shell script "date -r " & unixSecs & " +" & quoted form of unixFormatString & ""
		
	on error errMsg number errNum
		error "dateUnixFormat FAILED: " & errMsg number errNum
	end try
end dateUnixFormat

on NumberToString(bigNumber)
	-- by Paul Berkowitz
	
	set bigNumber to bigNumber as string
	if bigNumber does not contain "E+" then return bigNumber
	
	set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {"E+"}}
	try
		set {basicReal, powersOfTen} to {bigNumber's text item 1, (bigNumber's text item 2) as integer}
	on error -- e.g. Python strings have lower-case "e", tids case-sensitive
		set AppleScript's text item delimiters to {"e+"}
		set {basicReal, powersOfTen} to {bigNumber's text item 1, (bigNumber's text item 2) as integer}
	end try
	set AppleScript's text item delimiters to {"."}
	try
		set {integerPart, decimalPart} to basicReal's {text item 1, text item 2}
		set decimalSign to "."
	on error
		set AppleScript's text item delimiters to {","}
		set {integerPart, decimalPart} to basicReal's {text item 1, text item 2}
		set decimalSign to ","
	end try
	set AppleScript's text item delimiters to tids
	set n to count decimalPart
	if powersOfTen is greater than or equal to n then
		repeat (powersOfTen - n) times
			set decimalPart to decimalPart & "0"
		end repeat
		set bigNumber to integerPart & decimalPart
	else
		set bigNumber to integerPart & decimalPart
		set bigNumber to text 1 thru (powersOfTen + 1) of bigNumber & ¬
			decimalSign & text (powersOfTen + 2) thru -1 of bigNumber
	end if
	
	return bigNumber
	
end NumberToString

---
http://www.danshockley.com

[ Reply to This | # ]

COMPLEX script posted online
Authored by: Krioni on Aug 11, '09 07:53:41PM
OK. I was frustrated that my old script posted here was incorrect, so I put together a fairly complex script that does the following:

It allows you to run it, or use it as a droplet (save it as an Application from Script Editor). You can process multiple files/folders. You can change the modification date, the creation date, or both (with same or different new dates). It tries to use Apple's SetFile (comes with Developer Tools). If that is not available, it asks whether it can download and install ChangeFileDates by HAMSoft Engineering (they make it freely available, but do not support it), which it installs in ~/Library/Application Support/ChangeFileDates/

A copy of my script is on my website at http://www.danshockley.com/files/MacFileDatesChanger-1.1.applescript. I will also post it here in this comment, but it is pretty long, so going to the link and then saving the file might be easier than copy/paste.


-- MacFileDatesChanger
-- version 1.1
-- Daniel A. Shockley, http://www.danshockley.com
--    Includes some code from Paul Berkowitz and Nigel Garvey on applescript-users mailing list
--    May use or download/install ChangeFileDates, an unsupported command line tool, that
--     was made by HAMSoft Engineering. Read more at: 
--     http://www.hamsoftengineering.com/codeSharing/ChangeFileDates/ChangeFileDates.html
--   Will first attempt to use SetFile, found in Apple's Developer Tools

-- NOTES
-- Save this script as an application to enable drag-and-drop file/folder processing


-- VERSION HISTORY
-- 1.1 - posted online, initial release, not all errors captured
-- 1.0 - test version only

property ScriptName : "MacFileDatesChanger"
property dateFormatString : "%m/%d/%Y %H:%M:%S"
property debugMode : false


on open someItems
	-- someItems could be files or folders
	
	if (count of someItems) is 1 then
		if folder of (info for item 1 of someItems without size) then
			-- user dropped ONE folder on this, ask whether to modify it or contents
			
			display dialog "You dropped a single folder. Change date(s) of that Folder " & ¬
				" itself, or of its Contents?" buttons {"Cancel", "Folder", "Contents"} default button "Folder"
			if button returned of result is "Contents" then
				set oneFolder to item 1 of someItems
				tell application "Finder"
					set someItems to (items of oneFolder) as alias list
				end tell
			end if
			
		end if
	end if
	
	changeFileDates(someItems)
	
end open



on run
	set dialogMsg to "Choose a folder of files to change, or file(s)?"
	set buttonChoices to {"Cancel", "Folder", "Files"}
	set openChoice to button returned of (display dialog dialogMsg buttons buttonChoices default button "Files")
	
	if openChoice is "Files" then
		set chooseFileDialog to "Choose the file(s) you want to change:"
		set fileList to choose file with prompt chooseFileDialog with multiple selections allowed
		
	else if openChoice is "Folder" then
		set oneFolder to choose folder with prompt "Choose the folder whose contents (files/folders) you want to change:"
		tell application "Finder"
			set fileList to (items of oneFolder) as alias list
		end tell
	end if
	
	changeFileDates(fileList)
	
end run


on changeFileDates(fileList)
	
	set filePluralSingle to ""
	if (count of fileList) is greater than 1 then
		set filePluralSingle to "s"
	end if
	
	set dialogMsg to "Change Mod date, Creation date, or Both?"
	set buttonChoices to {"Mod", "Creation", "Both"}
	set dateChangeChoice to button returned of (display dialog dialogMsg buttons buttonChoices default button "Both")
	
	if dateChangeChoice is "Both" then
		set sameOrNot to button returned of (display dialog ¬
			"Change modification and creation to the Same or Different?" buttons ¬
			{"Cancel", "Different", "Same"} default button "Same")
		
		if sameOrNot is "Same" then
			set newDate to dateDialog("Please choose a new creation/mod date for the file" & filePluralSingle & ".")
			set newCreationDate to newDate
			set newModDate to newDate
		else -- Different, so ask for each
			set newCreationDate to dateDialog("Please choose a new creation date for the file" & filePluralSingle & ".")
			set modDateAsk to true
			
			set modDialog to "Please choose a new modification date for the file" & filePluralSingle & "."
			repeat while modDateAsk
				set newModDate to dateDialog(modDialog)
				if newModDate is less than newCreationDate then
					set modDialog to "The modification date can NOT be earlier than the creation date (" & ¬
						dateUnixFormat(newCreationDate, dateFormatString) & ")"
				else -- if it is not before creation, we're done
					set modDateAsk to false
				end if
			end repeat
			
		end if
		set changerPrefs to {doCreation:true, doMod:true, creationDateString:dateUnixFormat(newCreationDate, dateFormatString)} ¬
			& {modDateString:dateUnixFormat(newModDate, dateFormatString)}
		
		
		
	else if dateChangeChoice is "Creation" then
		set newCreationDate to dateDialog("Please choose a new creation date for the file" & filePluralSingle & ".")
		set changerPrefs to {doCreation:true, creationDateString:dateUnixFormat(newCreationDate, dateFormatString)}
	else if dateChangeChoice is "Mod" then
		set newModDate to dateDialog("Please choose a new modification date for the file" & filePluralSingle & ".")
		set changerPrefs to {doMod:true, modDateString:dateUnixFormat(newModDate, dateFormatString)}
	else -- should be impossible
	end if
	
	set cfdPosix to POSIX path of ((path to application support folder from user domain as text) & ¬
		"ChangeFileDates:ChangeFileDates")
	
	repeat with oneFilePath in fileList
		
		macFileDatesChanger(changerPrefs & {filePath:oneFilePath}) --& {binName:"ChangeFileDates", binPosix:cfdPosix})
		
	end repeat
	
end changeFileDates


on dateDialog(dialogMsg)
	-- for now, just handle files, not folders
	set chosenDate to date (text returned of (display dialog dialogMsg ¬
		default answer my dateUnixFormat(current date, dateFormatString)))
	return chosenDate
end dateDialog


on macFileDatesChanger(prefs)
	-- version 1.0, Daniel A. Shockley, http://www.danshockley.com
	
	set binPrefs to getBinaryInfo({installCFD:"ASK"}) -- need to 
	-- {binPosix:POSIX PATH TO BIN, binName:NAME OF BIN}
	set defaultPrefs to {doCreation:false, doMod:false, modDateString:"", creationDateString:""} & binPrefs
	
	if (class of prefs is not record) then
		error "macFileDatesChanger FAILED: parameter should be a single record, " & ¬
			"not just separated parameters." number 1024
	end if
	
	set prefs to prefs & defaultPrefs -- add on default preferences, if needed
	set filePath to filePath of prefs
	set binPosix to binPosix of prefs
	set binName to binName of prefs
	set doCreation to doCreation of prefs
	set creationDateString to creationDateString of prefs
	set doMod to doMod of prefs
	set modDateString to modDateString of prefs
	
	
	
	if binName is "SetFile" then
		set dateOptions to ""
		if doCreation then
			set dateOptions to "-d " & quoted form of creationDateString
		end if
		if doMod then
			set dateOptions to dateOptions & " -m " & quoted form of modDateString
		end if
		
		set shellCommand to binPosix & space & dateOptions & space & ¬
			quoted form of POSIX path of filePath
		
	else if binName is "ChangeFileDates" then
		
		if not doMod or not doCreation then
			-- need to get EXISTING dates, since tool needs both 
			set fileInfo to info for filePath without size
			set currentModDate to modification date of fileInfo
			set currentCreationDate to creation date of fileInfo
			if not doMod then set modDateString to dateUnixFormat(currentModDate, dateFormatString)
			if not doCreation then set creationDateString to dateUnixFormat(currentCreationDate, dateFormatString)
		end if
		
		set shellCommand to quoted form of binPosix & ¬
			" -cDate " & quoted form of creationDateString & " -mDate " & ¬
			quoted form of modDateString & " -file " & ¬
			quoted form of POSIX path of filePath
	end if
	
	try
		if debugMode then logConsole(ScriptName, "COMMAND: " & shellCommand)
		
		do shell script shellCommand
		
	on error theError number errorNumber
		display dialog "There was an error:" & return & theError & return & return & ¬
			"Error Number: " & errorNumber as text buttons {"OK"} default button 1 with icon stop
	end try
	
	
	
	
	
	
end macFileDatesChanger


on getBinaryInfo(installOptions)
	-- version 1.0, Daniel A. Shockley, http://www.danshockley.com
	-- Finds out whether SetFile is installed
	-- If not, looks for ChangeFileDates, by HAMSoft Engineering
	-- option to install
	
	set cfdPosix to POSIX path of ((path to application support folder from user domain as text) & ¬
		"ChangeFileDates:ChangeFileDates")
	
	-- Put possible places to look for binary tools into this list, first priority first
	set posixToTry to {"SetFile", "/Developer/Tools/SetFile", "/Developer/usr/bin/SetFile", "ChangeFileDates", cfdPosix}
	
	set foundBinPosix to tryBinPosixList(posixToTry)
	
	if length of foundBinPosix is greater than 0 then
		set binName to do shell script "basename " & quoted form of foundBinPosix
		
	else
		-- could not find it, see whether we are allowed to download and install
		if installCFD of installOptions is not "" then
			if installChangeFileDatesBinary(installOptions) then
				set foundBinPosix to POSIX path of ((path to application support folder from ¬
					user domain as text) & "ChangeFileDates:ChangeFileDates")
				set binName to "ChangeFileDates"
			else -- install failed or was not allowed
				error "Could not find a binary tool that allows creation date changing." number 1024
				
			end if
		end if
	end if
	
	return {binPosix:foundBinPosix, binName:binName}
	
end getBinaryInfo


on tryBinPosixList(posixList)
	
	repeat with tryPath in posixList
		set tryPath to contents of tryPath
		try
			do shell script quoted form of tryPath
		on error errMsg number errNum
			if errNum is 1 then
				-- binary was found, since nonexistence is 127
				return tryPath
			end if
		end try
	end repeat
	
	return ""
	
end tryBinPosixList


on installChangeFileDatesBinary(installOptions)
	-- version 1.0, Daniel A. Shockley, http://www.danshockley.com	
	if installCFD of installOptions is "YES" then
		-- don't ask, just allow to continue download and install
	else if installCFD of installOptions is "ASK" then
		display dialog "No binary tool for changing dates could be found. Attempt to download " & ¬
			"and install ChangeFileDates by HAMSoft Engineering (unsupported free tool)?" buttons {" Cancel ", "Install"}
		if button returned of result is " Cancel " then return false
		display dialog "You chose to download and install ChangeFileDates. It will be placed at " & ¬
			"~/Library/Application Support/ChangeFileDates/" & return & "Please Confirm that you wish to download " & ¬
			"and install ChangeFileDates." buttons {" Cancel ", "Confirm"} default button "Confirm"
		if button returned of result is " Cancel " then return false
	else
		return false
	end if
	
	-- only should get here if user CHOSE to allow, or if installCFD was "YES" 
	
	try
		set binaryURL to "http://www.hamsoftengineering.com/assets/ChangeFileDates.zip"
		set installToFolderPosix to POSIX path of ((path to application support folder from ¬
			user domain as text) & "ChangeFileDates:")
		
		set tmpZip to (do shell script "mktemp -t changefiledatesbinary")
		-- generate a random filepath to save zip
		-- (using the randomized temp-dir increases security)
		
		set curlCommand to "curl " & (quoted form of binaryURL) & space & "-o" & ¬
			space & tmpZip
		do shell script curlCommand
		
		set unzipCommand to "unzip " & quoted form of tmpZip & " -d " & quoted form of installToFolderPosix
		do shell script unzipCommand
		
	on error errMsg number errNum
		return false
	end try
	
	return true
	
end installChangeFileDatesBinary













on dateUnixFormat(theDate, unixFormatString)
	-- version 1.2, Daniel A. Shockley, http://www.danshockley.com
	-- includes code from Paul Berkowitz and Nigel Garvey on applescript-users mailing list
	-- updates suggested by Jonn8 on macscripter.net BBS
	
	-- dateUnixFormat DID NOT SEEM TO WORK with new Daylight Savings Time ! ! ! !
	-- BUT, subtracting an hour seems to fix it.
	
	-- run 'man strftime' in a shell to read the formatting options
	-- basics are: %d = dd, %m = mm, %Y = yyyy, %F = %Y-%m-%d, %M = MM (minutes), %H = HH (military), %S = SS
	
	try
		-- get the starting Unix date as an AppleScript date
		set theEpoch to (date (do shell script "date -r 0 '+%a %b %e %Y %H:%M:%S'"))
		set unixSecs to theDate - (theEpoch)
		
		set unixSecs to unixSecs - 1 * hours -- HACK to get around bug, seemingly caused by new DST
		
		set unixSecs to my NumberToString(unixSecs)
		
		set theDate to do shell script "date -r " & unixSecs & " +" & quoted form of unixFormatString & ""
		
	on error errMsg number errNum
		error "dateUnixFormat FAILED: " & errMsg number errNum
	end try
end dateUnixFormat

on NumberToString(bigNumber)
	-- by Paul Berkowitz
	
	set bigNumber to bigNumber as string
	if bigNumber does not contain "E+" then return bigNumber
	
	set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {"E+"}}
	try
		set {basicReal, powersOfTen} to {bigNumber's text item 1, (bigNumber's text item 2) as integer}
	on error -- e.g. Python strings have lower-case "e", tids case-sensitive
		set AppleScript's text item delimiters to {"e+"}
		set {basicReal, powersOfTen} to {bigNumber's text item 1, (bigNumber's text item 2) as integer}
	end try
	set AppleScript's text item delimiters to {"."}
	try
		set {integerPart, decimalPart} to basicReal's {text item 1, text item 2}
		set decimalSign to "."
	on error
		set AppleScript's text item delimiters to {","}
		set {integerPart, decimalPart} to basicReal's {text item 1, text item 2}
		set decimalSign to ","
	end try
	set AppleScript's text item delimiters to tids
	set n to count decimalPart
	if powersOfTen is greater than or equal to n then
		repeat (powersOfTen - n) times
			set decimalPart to decimalPart & "0"
		end repeat
		set bigNumber to integerPart & decimalPart
	else
		set bigNumber to integerPart & decimalPart
		set bigNumber to text 1 thru (powersOfTen + 1) of bigNumber & ¬
			decimalSign & text (powersOfTen + 2) thru -1 of bigNumber
	end if
	
	return bigNumber
	
end NumberToString



on logConsole(processName, consoleMsg)
	-- version 1.7 - Daniel A. Shockley, http://www.danshockley.com
	-- 1.7 - now works with Leopard by using the "logger" command instead of just appending to log file
	-- 1.6- the 'space' constant instead of literal spaces for readability, removed trailing space from the hostname command
	-- 1.5- uses standard date-stamp format	
	
	set shellCommand to "logger" & space & "-t" & space & quoted form of processName & space & quoted form of consoleMsg
	
	do shell script shellCommand
	return shellCommand
end logConsole


---
http://www.danshockley.com

[ Reply to This | # ]

COMPLEX script posted online
Authored by: bugs7007 on Jan 06, '10 02:14:00PM

Not sure if I'm doing this right or not but for some reason this script is ignoring the time, the date is set correctly but the time defaults to 16:00 (4:00p).

The date/time format I use is something like this: "10/10/2004 11:15:00".

I'm using this script with Snow Leopard.


--Sam



[ Reply to This | # ]
COMPLEX script posted online
Authored by: Krioni on Jul 07, '13 08:03:44PM

Here's another update - seems to work on Mountain Lion.

http://www.danshockley.com/files/MacFileDatesChanger-1.2.applescript

Sorry about the lack of line wrapping here - I worry that the line-continuation character in AppleScript (option-L) will get improperly converted to a different character, so I left the lines long instead.

Code:

-- MacFileDatesChanger
-- version 1.2
-- Daniel A. Shockley, http://www.danshockley.com
--    Code by Dan Shockley released under a BSD-3 license: (see http://opensource.org/licenses/BSD-3-Clause)
--      Basically, you can reuse and modify, with attribution in the source code. 
--    Execution may use or download/install ChangeFileDates, an unsupported command line tool, that
--     was made by HAMSoft Engineering. Read more at: 
--     http://www.hamsoftengineering.com/codeSharing/ChangeFileDates/ChangeFileDates.html
--   Will first attempt to use SetFile, found in Apple's Developer Tools

-- NOTES
-- Save this script as an application to enable drag-and-drop file/folder processing


-- VERSION HISTORY
-- 1.2 - (2013-07-07) updated to handle dates properly (uses ISO 8601, see http://xkcd.com/1179/); removed unnecessary code; updated license
-- 1.1 - posted online, initial release, not all errors captured
-- 1.0 - test version only

property ScriptName : "MacFileDatesChanger"
property dateFormatString : "YYYY-MM-DD hh:mm:ss" -- ISO 8601
property debugMode : false


on open someItems
	-- someItems could be files or folders
	
	if (count of someItems) is 1 then
		if folder of (info for item 1 of someItems without size) then
			-- user dropped ONE folder on this, ask whether to modify it or contents
			
			display dialog "You dropped a single folder. Change date(s) of that Folder itself, or of its Contents?" buttons {"Cancel", "Folder", "Contents"} default button "Folder"
			if button returned of result is "Contents" then
				set oneFolder to item 1 of someItems
				tell application "Finder"
					set someItems to (items of oneFolder) as alias list
				end tell
			end if
			
		end if
	end if
	
	changeFileDates(someItems)
	
end open


on run
	set dialogMsg to "Choose a folder of files to change, or file(s)?"
	set buttonChoices to {"Cancel", "Folder", "Files"}
	set openChoice to button returned of (display dialog dialogMsg buttons buttonChoices default button "Files")
	
	if openChoice is "Files" then
		set chooseFileDialog to "Choose the file(s) you want to change:"
		set fileList to choose file with prompt chooseFileDialog with multiple selections allowed
		
	else if openChoice is "Folder" then
		set oneFolder to choose folder with prompt "Choose the folder whose contents (files/folders) you want to change:"
		tell application "Finder"
			set fileList to (items of oneFolder) as alias list
		end tell
	end if
	
	changeFileDates(fileList)
	
end run


on changeFileDates(fileList)
	
	set filePluralSingle to ""
	if (count of fileList) is greater than 1 then
		set filePluralSingle to "s"
	end if
	
	set dialogMsg to "Change Mod date, Creation date, or Both?"
	set buttonChoices to {"Mod", "Creation", "Both"}
	set dateChangeChoice to button returned of (display dialog dialogMsg buttons buttonChoices default button "Both")
	
	if dateChangeChoice is "Both" then
		set sameOrNot to button returned of (display dialog "Change modification and creation to the Same or Different?" buttons {"Cancel", "Different", "Same"} default button "Same")
		
		if sameOrNot is "Same" then
			set newDate to dateDialog("Please choose a new creation/mod date for the file" & filePluralSingle & ".")
			set newCreationDate to newDate
			set newModDate to newDate
		else -- Different, so ask for each
			set newCreationDate to dateDialog("Please choose a new creation date for the file" & filePluralSingle & ".")
			set modDateAsk to true
			
			set modDialog to "Please choose a new modification date for the file" & filePluralSingle & "."
			repeat while modDateAsk
				set newModDate to dateDialog(modDialog)
				if newModDate is less than newCreationDate then
					set modDialog to "The modification date can NOT be earlier than the creation date (" & dateAsCustomString(newCreationDate, dateFormatString) & ")"
				else -- if it is not before creation, we're done
					set modDateAsk to false
				end if
			end repeat
			
		end if
		set changerPrefs to {doCreation:true, doMod:true, creationDateString:dateAsCustomString(newCreationDate, dateFormatString)} & {modDateString:dateAsCustomString(newModDate, dateFormatString)}
		
		
		
	else if dateChangeChoice is "Creation" then
		set newCreationDate to dateDialog("Please choose a new creation date for the file" & filePluralSingle & ".")
		set changerPrefs to {doCreation:true, creationDateString:dateAsCustomString(newCreationDate, dateFormatString)}
	else if dateChangeChoice is "Mod" then
		set newModDate to dateDialog("Please choose a new modification date for the file" & filePluralSingle & ".")
		set changerPrefs to {doMod:true, modDateString:dateAsCustomString(newModDate, dateFormatString)}
	else -- should be impossible
	end if
	
	set cfdPosix to POSIX path of ((path to application support folder from user domain as text) & "ChangeFileDates:ChangeFileDates")
	
	repeat with oneFilePath in fileList
		
		macFileDatesChanger(changerPrefs & {filePath:oneFilePath}) --& {binName:"ChangeFileDates", binPosix:cfdPosix})
		
	end repeat
	
end changeFileDates


on dateDialog(dialogMsg)
	set chosenDateAsISO8601 to (text returned of (display dialog dialogMsg & return & "[Dates in ISO 8601 format: YYYY-MM-DD hh:mm:ss format!]" default answer my dateAsCustomString(current date, dateFormatString)))
	set chosenDate to dateFromISO8601(chosenDateAsISO8601)
	return chosenDate
end dateDialog


on macFileDatesChanger(prefs)
	-- version 1.1, Daniel A. Shockley, http://www.danshockley.com
	
	-- 1.1 - updated so that the incoming parameter dates are ISO 8601, but converted to format needed by SetFile or ChangeFileDates
	
	set commandDateFormat to "MM/DD/YYYY hh:mm:ss"
	
	set binPrefs to getBinaryInfo({installCFD:"ASK"}) -- need to 
	-- {binPosix:POSIX PATH TO BIN, binName:NAME OF BIN}
	set defaultPrefs to {doCreation:false, doMod:false, modDateString:"", creationDateString:""} & binPrefs
	
	if (class of prefs is not record) then
		error "macFileDatesChanger FAILED: parameter should be a single record, " & "not just separated parameters." number 1024
	end if
	
	set prefs to prefs & defaultPrefs -- add on default preferences, if needed
	set filePath to filePath of prefs
	set binPosix to binPosix of prefs
	set binName to binName of prefs
	set doCreation to doCreation of prefs
	set doMod to doMod of prefs
	
	
	set creationDateString to creationDateString of prefs
	set modDateString to modDateString of prefs
	
	if length of creationDateString is greater than 0 then
		set creationDateString to dateFromISO8601(creationDateString)
		set creationDateString to dateAsCustomString(creationDateString, commandDateFormat)
	end if
	if length of modDateString is greater than 0 then
		set modDateString to dateFromISO8601(modDateString)
		set modDateString to dateAsCustomString(modDateString, commandDateFormat)
	end if
	
	
	if binName is "SetFile" then
		set dateOptions to ""
		if doCreation then
			set dateOptions to "-d " & quoted form of creationDateString
		end if
		if doMod then
			set dateOptions to dateOptions & " -m " & quoted form of modDateString
		end if
		
		set shellCommand to binPosix & space & dateOptions & space & quoted form of POSIX path of filePath
		
	else if binName is "ChangeFileDates" then
		
		if not doMod or not doCreation then
			-- need to get EXISTING dates, since tool needs both 
			set fileInfo to info for filePath without size
			set currentModDate to modification date of fileInfo
			set currentCreationDate to creation date of fileInfo
			if not doMod then set modDateString to dateAsCustomString(currentModDate, dateFormatString)
			if not doCreation then set creationDateString to dateAsCustomString(currentCreationDate, dateFormatString)
		end if
		
		set shellCommand to quoted form of binPosix & " -cDate " & quoted form of creationDateString & " -mDate " & quoted form of modDateString & " -file " & quoted form of POSIX path of filePath
	end if
	
	try
		if debugMode then logConsole(ScriptName, "COMMAND: " & shellCommand)
		
		do shell script shellCommand
		
	on error theError number errorNumber
		display dialog "There was an error:" & return & theError & return & return & "Error Number: " & errorNumber as text buttons {"OK"} default button 1 with icon stop
	end try
	
end macFileDatesChanger


on getBinaryInfo(installOptions)
	-- version 1.0, Daniel A. Shockley, http://www.danshockley.com
	-- Finds out whether SetFile is installed
	-- If not, looks for ChangeFileDates, by HAMSoft Engineering
	-- option to install
	
	set cfdPosix to POSIX path of ((path to application support folder from user domain as text) & "ChangeFileDates:ChangeFileDates")
	
	-- Put possible places to look for binary tools into this list, first priority first
	set posixToTry to {"SetFile", "/Developer/Tools/SetFile", "/Developer/usr/bin/SetFile", "ChangeFileDates", cfdPosix}
	
	set foundBinPosix to tryBinPosixList(posixToTry)
	
	if length of foundBinPosix is greater than 0 then
		set binName to do shell script "basename " & quoted form of foundBinPosix
		
	else
		-- could not find it, see whether we are allowed to download and install
		if installCFD of installOptions is not "" then
			if installChangeFileDatesBinary(installOptions) then
				set foundBinPosix to POSIX path of ((path to application support folder from user domain as text) & "ChangeFileDates:ChangeFileDates")
				set binName to "ChangeFileDates"
			else -- install failed or was not allowed
				error "Could not find a binary tool that allows creation date changing." number 1024
				
			end if
		end if
	end if
	
	return {binPosix:foundBinPosix, binName:binName}
	
end getBinaryInfo


on tryBinPosixList(posixList)
	
	repeat with tryPath in posixList
		set tryPath to contents of tryPath
		try
			do shell script quoted form of tryPath
		on error errMsg number errNum
			if errNum is 1 then
				-- binary was found, since nonexistence is 127
				return tryPath
			end if
		end try
	end repeat
	
	return ""
	
end tryBinPosixList


on installChangeFileDatesBinary(installOptions)
	-- version 1.0, Daniel A. Shockley, http://www.danshockley.com	
	if installCFD of installOptions is "YES" then
		-- don't ask, just allow to continue download and install
	else if installCFD of installOptions is "ASK" then
		display dialog "No binary tool for changing dates could be found. Attempt to download " & "and install ChangeFileDates by HAMSoft Engineering (unsupported free tool)?" buttons {" Cancel ", "Install"}
		if button returned of result is " Cancel " then return false
		display dialog "You chose to download and install ChangeFileDates. It will be placed at " & "~/Library/Application Support/ChangeFileDates/" & return & "Please Confirm that you wish to download " & "and install ChangeFileDates." buttons {" Cancel ", "Confirm"} default button "Confirm"
		if button returned of result is " Cancel " then return false
	else
		return false
	end if
	
	-- only should get here if user CHOSE to allow, or if installCFD was "YES" 
	
	try
		set binaryURL to "http://www.hamsoftengineering.com/assets/ChangeFileDates.zip"
		set installToFolderPosix to POSIX path of ((path to application support folder from user domain as text) & "ChangeFileDates:")
		
		set tmpZip to (do shell script "mktemp -t changefiledatesbinary")
		-- generate a random filepath to save zip
		-- (using the randomized temp-dir increases security)
		
		set curlCommand to "curl " & (quoted form of binaryURL) & space & "-o" & space & tmpZip
		do shell script curlCommand
		
		set unzipCommand to "unzip " & quoted form of tmpZip & " -d " & quoted form of installToFolderPosix
		do shell script unzipCommand
		
	on error errMsg number errNum
		return false
	end try
	
	return true
	
end installChangeFileDatesBinary



on dateFromISO8601(stringISO8601)
	-- version 1.0, Daniel A. Shockley
	-- based on code suggested by sakra, at http://stackoverflow.com/a/7215104
	set convertedDate to (current date)
	set {oldDelims, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {"-", "T", ":", space}}
	set {convertedDate's year, convertedDate's month, convertedDate's day, convertedDate's hours, convertedDate's minutes, convertedDate's seconds} to ((every text item of stringISO8601) & {0, 0, 0})
	set AppleScript's text item delimiters to oldDelims
	return convertedDate
end dateFromISO8601


on dateAsCustomString(incomingDate, stringFormat)
	-- version 1.5, Daniel A. Shockley http://www.danshockley.com
	
	-- VERSION HISTORY
	-- 1.5 - uses replaceSimple 1.4, updated for more recent OS versions
	-- 1.4 - uses replaceSimple 1.2, which handles considering case by default in Snow Leopard
	-- 1.3 - uses replaceSimple, rather than simpleReplace (name-change issue)
	-- 1.2 - added am/pm option, and date class checking, with a nod to Arthur J. Knapp
	-- NEEDS replaceSimple() handler
	
	-- takes any form of MM, DD, YYYY, YY
	-- AND any form of hh, mm, ss 
	--  (optional ap or AP, which gives am/pm or AM/PM)
	-- leaving off am/pm option coerces to military time
	-- MUST USE LOWER-CASE for TIME!!!! (avoids month/minute conflict)
	
	-- use single letters to allow single digits, where applicable
	
	-- textVars are each always 2 digits, whereas month and day 
	-- may be 1 digit, and year will normally be 4 digit
	
	if class of incomingDate is not date then
		try
			set incomingDate to date incomingDate
		on error
			set incomingDate to (current date)
		end try
	end if
	
	set numHours to (time of incomingDate) div hours
	set textHours to text -2 through -1 of ("0" & (numHours as string))
	
	set numMinutes to (time of incomingDate) mod hours div minutes
	set textMinutes to text -2 through -1 of ("0" & (numMinutes as string))
	
	set numSeconds to (time of incomingDate) mod minutes
	set textSeconds to text -2 through -1 of ("0" & (numSeconds as string))
	
	set numDay to day of incomingDate as number
	set textDay to text -2 through -1 of ("0" & (numDay as string))
	
	set numYear to year of incomingDate as number
	set textYear to text -2 through -1 of (numYear as string)
	
	-- Emmanuel Levy's Plain Vanilla get month number function
	copy incomingDate to b
	set the month of b to January
	set numMonth to (1 + (incomingDate - b + 1314864) div 2629728)
	set textMonth to text -2 through -1 of ("0" & (numMonth as string))
	
	set customDateString to stringFormat
	
	if numHours > 12 and (customDateString contains "ap" or customDateString contains "AP") then
		-- (afternoon) and requested am/pm
		set numHours to numHours - 12 -- pull off the military 12 hours for pm hours
		set textHours to text -2 through -1 of ("0" & (numHours as string))
	end if
	
	set customDateString to replaceSimple({customDateString, "MM", textMonth})
	set customDateString to replaceSimple({customDateString, "DD", textDay})
	set customDateString to replaceSimple({customDateString, "YYYY", numYear as string})
	set customDateString to replaceSimple({customDateString, "hh", textHours})
	
	set customDateString to replaceSimple({customDateString, "mm", textMinutes})
	set customDateString to replaceSimple({customDateString, "ss", textSeconds})
	
	
	-- shorter options
	set customDateString to replaceSimple({customDateString, "M", numMonth})
	set customDateString to replaceSimple({customDateString, "D", numDay})
	set customDateString to replaceSimple({customDateString, "YY", textYear})
	set customDateString to replaceSimple({customDateString, "h", numHours})
	set customDateString to replaceSimple({customDateString, "m", numMinutes})
	set customDateString to replaceSimple({customDateString, "s", numSeconds})
	
	-- AM/PM MUST be after Minutes/Month done, since it adds an M
	if (time of incomingDate) > (12 * hours) then
		-- afternoon
		set customDateString to replaceSimple({customDateString, "ap", "pm"})
		set customDateString to replaceSimple({customDateString, "AP", "PM"})
	else
		set customDateString to replaceSimple({customDateString, "ap", "am"})
		set customDateString to replaceSimple({customDateString, "AP", "AM"})
	end if
	
	return customDateString
	
end dateAsCustomString




on replaceSimple(prefs)
	-- version 1.4, Daniel A. Shockley http://www.danshockley.com
	
	-- 1.4 - Convert sourceText to string, since the previous version failed on numbers. 
	-- 1.3 - The class record is specified into a variable to avoid a namespace conflict when run within FileMaker. 
	-- 1.2 - changes parameters to a record to add option to CONSIDER CASE, since the default changed to ignoring case with Snow Leopard. This handler defaults to CONSIDER CASE = true, since that was what older code expected. 
	-- 1.1 - coerces the newChars to a STRING, since other data types do not always coerce
	--     (example, replacing "nine" with 9 as number replaces with "")
	
	set defaultPrefs to {considerCase:true}
	
	if class of prefs is list then
		if (count of prefs) is greater than 3 then
			-- get any parameters after the initial 3
			set prefs to {sourceText:item 1 of prefs, oldChars:item 2 of prefs, newChars:item 3 of prefs, considerCase:item 4 of prefs}
		else
			set prefs to {sourceText:item 1 of prefs, oldChars:item 2 of prefs, newChars:item 3 of prefs}
		end if
		
	else if class of prefs is not equal to (class of {someKey:3}) then
		-- Test by matching class to something that IS a record to avoid FileMaker namespace conflict with the term "record"
		
		error "The parameter for 'replaceSimple()' should be a record or at least a list. Wrap the parameter(s) in curly brackets for easy upgrade to 'replaceSimple() version 1.3. " number 1024
		
	end if
	
	
	set prefs to prefs & defaultPrefs
	
	
	set considerCase to considerCase of prefs
	set sourceText to sourceText of prefs
	set oldChars to oldChars of prefs
	set newChars to newChars of prefs
	
	set sourceText to sourceText as string
	
	set oldDelims to AppleScript's text item delimiters
	set AppleScript's text item delimiters to the oldChars
	if considerCase then
		considering case
			set the parsedList to every text item of sourceText
			set AppleScript's text item delimiters to the {(newChars as string)}
			set the newText to the parsedList as string
		end considering
	else
		ignoring case
			set the parsedList to every text item of sourceText
			set AppleScript's text item delimiters to the {(newChars as string)}
			set the newText to the parsedList as string
		end ignoring
	end if
	set AppleScript's text item delimiters to oldDelims
	return newText
	
	
end replaceSimple



on logConsole(processName, consoleMsg)
	-- version 1.7 - Daniel A. Shockley, http://www.danshockley.com
	-- 1.7 - now works with Leopard by using the "logger" command instead of just appending to log file
	-- 1.6- the 'space' constant instead of literal spaces for readability, removed trailing space from the hostname command
	-- 1.5- uses standard date-stamp format	
	
	set shellCommand to "logger" & space & "-t" & space & quoted form of processName & space & quoted form of consoleMsg
	
	do shell script shellCommand
	return shellCommand
end logConsole



[ Reply to This | # ]
How about adding or subtracting time from creation dates?
Authored by: strangeluck on Jul 07, '06 07:56:22PM

This is helpful, but what I really need is a way to say "subtract 1 yr 3 days and 10 seconds from all the creation dates in this folder." Anyone have any suggestions?

Thanks...



[ Reply to This | # ]
How about adding or subtracting time from creation dates?
Authored by: alexorso on Jul 10, '06 06:25:30PM
If you don't need a GUI-based tool, you can use JHead (http://www.sentex.net/~mwandel/jhead/). I use it every time I have to put together pictures taken with different cameras to sync the pictures' timestamps. It always worked great for me.

[ Reply to This | # ]
How about adding or subtracting time from creation dates?
Authored by: ctierney on Jan 03, '07 11:17:47AM
If your date utility supports the -d option, then you might try something like:
date -d'2005-02-03 - 1 year 2 days 10 seconds ago'
I'm still at 10.3.9 and can confirm that the out of the box date utility does not support this. But maybe 10.4 does(?).

[ Reply to This | # ]
How about adding or subtracting time from creation dates?
Authored by: Cezary Okupski on May 19, '09 10:03:10PM
Install exiftool (http://www.sno.phy.queensu.ca/~phil/exiftool/#shift) and then in the command line:
exiftool '-FileModifyDate-=1:0:3 0:0:10' DIR
or if you want to modify (or set) metadata dates as well then for example:
exiftool '-AllDates-=1:0:3 0:0:10' DIR
There is so much more functionality to manage photos, so it's worth to have a read about it.

[ Reply to This | # ]
use filename for creation date info?
Authored by: Florrie on Jul 11, '06 03:26:23AM

Hi, this works great! But I have one more question, since I'm not an ApplScript guru (on the contrary, I know almost nothing about it!):
I save my picture files with the creation date in the filename, for exaple, a scanned slide with no. 36, taken on december 25th 1997 would have this filename:

RCR_19971225_AA36.psd

Would it be possible to change the script, so that it can recognize the date between the underscores and use that as timestamp?

Thank you!



[ Reply to This | # ]
use filename for creation date info?
Authored by: spacericker9k on Jul 11, '06 09:07:13AM

here you go....
-save it as an application using script editor
-to use, drag and drop files onto it
-very important...the script assumes that underscores separate the date AND that the date is the second piece of info in the filename. as in: RCR_19971225_AA36.psd
-it also assumes that the date in the filename is formatted as YYYYMMDD
-for the hour and minute part, the script adds 0000, which is 12:00am

on open files_
repeat with file_ in files_
tell application "Finder"
set file_name to name of file_
set AppleScript's text item delimiters to {"_"}
set new_creation_date to second text item of file_name
set new_creation_date to new_creation_date & "0000"
set file_ to POSIX path of file_
do shell script "touch -t " & new_creation_date & " " & quoted form of file_
end tell
end repeat
end open



[ Reply to This | # ]
recommend restoring AS TIDS
Authored by: Krioni on Jul 13, '06 04:02:25PM
I always recommend restoring the AppleScript's text item delimiters to whatever they were before changing them (just in case you use this in a subscript):


on open files_
	repeat with file_ in files_
		tell application "Finder"
			set file_name to name of file_
			set od to AppleScript's text item delimiters
			set AppleScript's text item delimiters to {"_"}
			set new_creation_date to second text item of file_name
			set new_creation_date to new_creation_date & "0000"
			set file_ to POSIX path of file_
			do shell script "touch -t " & new_creation_date & " " & quoted form of file_
			set AppleScript's text item delimiters to od
		end tell
	end repeat
end open

---
http://www.danshockley.com

[ Reply to This | # ]

recommend restoring AS TIDS
Authored by: ctierney on Jan 03, '07 10:00:34AM
That's good advice to restore TIDS. Here's another method that off loads the filename parsing to sed. Not nearly as readable, but any non digit can be the delimiter:
on open files_
	repeat with file_ in files_
		tell application "Finder"
			set file_name to name of file_
			set file_ to POSIX path of file_
			do shell script "touch -t `echo " & file_name & " | sed -ne 's/.*\\([0-9]\\{8,8\\}\\).*/\\10000/p'` \"" & file_ & "\""
		end tell
	end repeat
end open


[ Reply to This | # ]
change date/time - different format
Authored by: idarryl on Feb 06, '08 07:33:11AM

Hi Guys,

(sucking up section - skip ahead for the real question)
I'm sorry to bug you - I'm sure you don't want to write personalised scripts for everyone, however I have been trying to figure something out for myself for a few hours now using your *wonderful* scripts as a head start, and I just can't work it out.


I'm trying to do the same thing but with iChat log files, the file format is a little more difficult "Persons Name on 2007-08-04 at 13.56.ichat", if possible I would like to set the time as well, as iChat logs are pretty time sensitive for me.

Unfortunately, when I moved ove to Leopard, the date and time were reset!!

Thanks for your help



[ Reply to This | # ]
An AppleScript droplet to change the creation date
Authored by: BaronKen on Jul 27, '06 08:49:17AM

Instead of a dialog asking for a date, how about using the EXIF creation date (from the picture file) to set the file(?) creation date? (new to AppleScript, so I have no idea if/how it can be done).



[ Reply to This | # ]
An AppleScript droplet to change the creation date
Authored by: morespace54 on Jul 27, '06 11:13:56AM

Well, if you use iPhoto 6, you can do just that.

1. First, create an album (ex. Birthday 1985)
2. Import desired pictures in that album
3. Select all the pictures from that album (cmd+a)
4. Use the option "Batch (whatever)". If you do the right-click you will see that option (It's in a menu as well but I can't remember which one).
Then, you can change the creation dates (or comments) for all those pictures. Voilà !

The real deal is that iPhoto allows you to add, let say, 2 minutes between each pictures.

So
Picture 01 became 1985/05/03 10:00 AM
Picture 02 became 1985/05/03 10:02 AM
etc.



[ Reply to This | # ]
An AppleScript droplet to change the creation date
Authored by: BaronKen on Aug 07, '06 12:13:44PM

Don't you have to type in a date to change them that way? I want it to automatically use the EXIF creation date (which I wouldn't know unless I looked at the EXIF properties individually).

Thanks.



[ Reply to This | # ]
An AppleScript droplet to change the creation date
Authored by: Darkelf on Nov 06, '06 09:07:45AM

Have an interesting problem with these scripts.

Seems that certain jpg files are resistant to the date change. The modified date works just fine in both scripts listed but on some files the creation date will only respond to a date *prior* to its current creation date.

In trying to make the problem clear, here is an example.

File name= testpic.jpg mod date= 1/1/2003 creation date = 7/23/2000

If I try to change the creation date to lets say 8/24/05, only the modified date will update.

If I try to change the creation date to something earlier, lets say 6/15/2000, then it works just fine, changing both creation and modified dates.

Weird. Any ideas how to fix this? I really need this script to work as I have a whole lot of pix that need organizing and the batch edit in iPhoto only modifies a duplicate of the original. Need to change the original.

Thanks!!



[ Reply to This | # ]
An AppleScript droplet to change the creation date
Authored by: Skeeve on Jan 01, '07 08:19:49AM

Simple: In Terminal do
cat oldfile.jpg > newfile.jpg
After that you have the current date set for newfile.jpg and can touch it to any ancient date you like. oldfile.jpg is obsolete then.



[ Reply to This | # ]
An AppleScript droplet to change the creation date
Authored by: MikeyMike on Feb 08, '07 03:31:55AM

Doesn't work!

Changes modification date, not creation date. As does the more complex script posted as a reply.

:-(



[ Reply to This | # ]
An AppleScript droplet to change the creation date
Authored by: JimDaGeek on Jun 22, '07 12:27:29PM
These scripts only change the access/modification times.

From man touch:
-t Change the access and modification times to the specified time.

The -t option does not change creation date/time.

[ Reply to This | # ]

An AppleScript droplet to change the creation date
Authored by: Gregory on Jul 12, '08 07:39:25AM

the easiest solution for me was to use File Buddy which has options to change the Creation Date (and the Modification Date if you wish) to a specific date, or by a specific adjustment. I was able to very easily adjust the creation dates of all of my audio files created while my MBP was in an incorrect time zone; all of them 15 hours off.



[ Reply to This | # ]
An AppleScript droplet to change the creation date
Authored by: Dougist on Feb 12, '09 04:01:18AM

Ummm...Not sure what the last few posts are about. The script(s) both work for me in changing the Created Date on RTF/RTFD/PDFs and folders. I did not try them on image files.

The first shorter script will also changes the creation date of folders. The second, longer script only changes the dates of files and will not change a folder date.

(To change a folder date drop the empty folder on the droplet)

Thanks very much for the scripts. They are much more affordable than a $30 utility.

Anyone care to modify them to run as scripts against selected files rather than as droplets, and perhaps combining the capability to change dates on folders of the first script with the more elegant coding of the second one?



[ Reply to This | # ]
An AppleScript droplet to change the creation date
Authored by: mannyotr on Nov 19, '09 03:58:26PM

This is pretty cool, but I am looking for an easy script that changes the Modified Date (with the Creation Date) of a Folder. Not the files inside the folder, but the actual folder itself. Would love if I could select a few folders and have the script modify the dates of all at once.

Any help will be greatly appreciated!



[ Reply to This | # ]
An AppleScript droplet to change the creation date
Authored by: Fairly on Jun 03, '10 08:31:02AM

Why? Why would anyone want to change this date? Also I'm not sure whether this corresponds to the old HFS+ create field or is actually the new FreeBSD birthdate. But as it's not immutable, why change it? There are myriad applications available that already do this (and more) anyway.



[ Reply to This | # ]
An AppleScript droplet to change the creation date
Authored by: andrewwynn on Jun 10, '10 09:19:34PM

the easiest way to perform this function is using graphic converter; right-click on a file while browsing and pick metadata->exif->set creation date based on EXIF.

(i prefer to use the creation date vs both; then you can keep track of edits but also sort by the original date of capture).

and to answer the question of why bother; duh ; since sorting by date is done by FILE date in most programs and even in iPhoto, internally the files are stored based on file date vs exif date; it's far cleaner when the dates are correct first.



[ Reply to This | # ]
An AppleScript droplet to change the creation date
Authored by: mshaub on Jan 08, '11 06:59:47AM

I just found that Picasa for OSX has this date adjusting function under the "Tools" menu. It changed the creation date but not the modified date of the photo I tried. I'm hoping to adjust some stitched panorama photos back to the date and time of the originals. It doesn't seem to change the EXIF data. It's a nice free and very GUI option for me.



[ Reply to This | # ]
I only get an error message in return
Authored by: invenio on Dec 30, '11 04:10:24AM
When I execute the script I get to the stage where I'm asked whether I want to change the Mod date, Creation date or Both. Selecting say the "Creation date" returns the error message:

error "dateUnixFormat FAILED: Invalid date and time date Thu Jan  1 1970 10:00:00." number -30720 from «script» to item

Events and replies are:

tell application "AppleScript Editor"
	display dialog "Choose a folder of files to change, or file(s)?" buttons {"Cancel", "Folder", "Files"} default button "Files"
		--> {button returned:"Files"}
	choose file with prompt "Choose the file(s) you want to change:" with multiple selections allowed
		--> {alias "Macintosh HD:Users:Mack:Documents:TestFile.txt"}
	display dialog "Change Mod date, Creation date, or Both?" buttons {"Mod", "Creation", "Both"} default button "Both"
		--> {button returned:"Creation"}
end tell
tell current application
	current date
		--> date "Friday, 30 December 2011 11:04:28 PM"
	do shell script "date -r 0 '+%a %b %e %Y %H:%M:%S'"
		--> "Thu Jan  1 1970 10:00:00"
Any idea why?

[ Reply to This | # ]