I had this working earlier but somehow I lost it.
In this script I change the creation dates to a series of new dates with user-definable intervals. Two things I haven’t been able to figure out yet.
- How to multiply a variable with ‘minutes’, ‘seconds’ etc.
- If the files are loaded, the order with which they chance should be based on their current file name. I have no idea how to accomplish that.
Any help would be appreciated by this newbie
PS StefanK, thanks for the help earlier!
The code:
property incrAmount : missing value
property incrUnit : missing value
property lcUnit : missing value
property incrMultiplier : missing value
property newMultiplier : missing value
property newCreationDate : missing value
on open fileList
set dialogMsg to "Please enter new creation (DD MM YYYY):"
set newCreationDate to date (text returned of (display dialog dialogMsg default answer ""))
set optionsList to {"Seconds", "Minutes", "Hours", "Days", "Weeks", "Months"}
set incrUnit to (choose from list optionsList with prompt "Choose interval...")
if incrUnit is false then return
set incrUnit to item 1 of incrUnit
if incrUnit is "Seconds" then
set incrMultiplier to 1 as integer
set lcUnit to "seconds"
else if incrUnit is "Minutes" then
set incrMultiplier to 60 as integer
set lcUnit to "minutes"
else if incrUnit is "Hours" then
set incrMultiplier to 3600 as integer
set lcUnit to "hours"
else if incrUnit is "Days" then
set incrMultiplier to 86400 as integer
set lcUnit to "days"
else if incrUnit is "Weeks" then
set incrMultiplier to 604800 as integer
set lcUnit to "weeks"
else if incrUnit is "Months" then
set incrMultiplier to 1 as integer
set lcUnit to "months"
end if
set dialogMsg2 to "Enter interval duration in " & lcUnit
set incrAmount to text returned of (display dialog dialogMsg2 default answer "1")
set newMultiplier to incrMultiplier * incrAmount
-- display dialog "newMultiplier = " & newMultiplier
changeCreationDate(fileList)
end open
on changeCreationDate(fileList)
-- Idea from Daniel A. Shockley (http://www.danshockley.com) on macosxhints.com
repeat with oneItem in fileList
if folder of (info for oneItem without size) is false then
set shellCommand to "touch -t " & " " & quoted form of POSIX path of oneItem -- set to current date
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)
set shellCommand to "touch -t " & creationDateString & " " & quoted form of POSIX path of oneItem
-- Add increments to date for next file in line
set newMultiplier to integer newMultiplier
if incrUnit is "Months" then
set newCreationDate to newCreationDate + (newMultiplier * months)
else
set newCreationDate to newCreationDate + (newMultiplier * seconds)
end if
do shell script shellCommand
end if
end repeat
end changeCreationDate
on getMonthNum(theDate)
-- From Nigel Garvey
--set theDate to the current date --or any other date
copy theDate to b
set the month of b to January
set monthNum to (theDate - b + 3944592) div 2629728
return monthNum
end getMonthNum