I am trying to write a script that will prompt me to name files when I add them to a folder. I am fine with the dialog box and everything, but how do I tell applescript to “target” the file with the newest creation date? as it is the file I am adding, i want to change its name only.
I’m not sure if this is what you’re asking for but the following handler will take a list of dates and return the index of the latest date. Since it works with a repeat loop, you might want to integrate the logic into whatever repeat loop you have when enumerating through the files to compare.
on latestModIndex(compareDates)
set latestDateIndex to 0
set compareDate to date "Wednesday, January 1, 1800 12:00:00 AM"
repeat with i from 1 to count of compareDates
set thisDate to item i of compareDates
if thisDate > compareDate then
set compareDate to thisDate
set latestDateIndex to i
end if
end repeat
return latestDateIndex
end latestModIndex
hmmmm…well, that was a bit helpful, but I’m just trying to make a basic script here. It will be a folder action script so that when I add a file to the folder, a dialog box appears, asks me what to name the file, and then changes its name. I just need it to target the file I’m adding.
I tried to do this with a folder action and when a newly added file was renamed (via a dialog), the renamed file tripped the folder action again, producing a dialog for the file that was just renamed.