Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

SavMBP15

macrumors 6502
Original poster
Mar 26, 2010
371
6
I have a repetitive task I would like to automate.

I download four files and I want to rename them based on their date modified. (I use iMacro to download the files for me, but because the website I download from uses JS to initiate the DL, I cannot get iMacro to rename them).

Assumptions:
- It will always be four files
- The original four file names will change each time (there is not pattern to these names)
- The names I want to change to, will always be the same, based on the date/time modified (which is really date/time downloaded))

So as an example I download the following four files to my download folder:
Name Date Modified
abc123.csv Today, 8:50:32 pm
def456.csv Today, 8:50:51 pm
ghi789.cv Today, 8:51:03 pm
jkl012.csv Today, 8:51:12 pm

I want to rename these four files from the earliest date modified to the latest date modified to (these names will never change):
earliest.csv
earliest1.csv
later.csv
latest.csv

Ultimately each time I download the four files and run this script it will begin to rename each file based on the earliest file to whatever I want and then go to the next one and so on.

Any ideas?

Matt
 
Your post is confusing. You talk about date/time modified but I think you mean creation date. You also say these names will never change e.g earliest.csv etc but then you say rename each file based on the earliest file to whatever I want. Anyway, here's an AppleScript example to get you going :

Code:
set newFileNames to {"earliest", "earliest1", "later", "latest"}
tell application "Finder"
    set fileList to every file of folder "Test" of home as alias list
    set sortedList to sort fileList by creation date
    repeat with i from 1 to number of items in sortedList
        set this_item to item i of sortedList
        set this_item_ext to name extension of this_item
        set name of this_item to item i of newFileNames & "." & this_item_ext
    end repeat
end tell

You can test this by creating a folder named Test in your home folder and copy the 4 files into it. You can also adapt it to be used as an Automator Service.
 
  • Like
Reactions: superscape
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.