Date in Filename

Summary: Appends the “Date Added” to the filenames of the selected records.
Requires: EagleFiler
Install Location: ~/Library/Scripts/Applications/EagleFiler/
Last Modified: 2019-10-02

Description

If you import a bunch of identically named files, you’ll get a bunch of identically named records (with a counter) in the library. This script lets you add the date to the end of the filename to help keep track of which is which, and to improve the sort order.

Installation Instructions · Download in Compiled Format · Download in Text Format

Script

tell application "EagleFiler"
    
set _records to selected records of browser window 1
    
tell library document 1
        
repeat with _record in _records
            
set _base to _record's title
            
set _dateString to my dateStringFromDate(_record's added date)
            
set _newName to _base & " " & _dateString
            
set filename of _record to _newName
        
end repeat
    
end tell
end tell

on dateStringFromDate(_date) -- YYYY-MM-DD
    
set _year to year of _date as string
    
set _month to my pad((month of _date as integer) as string)
    
set _day to my pad(day of _date as string)
    
return _year & "-" & _month & "-" & _day
end dateStringFromDate

on pad(_string)
    
if length of _string is 1 then
        
set _string to "0" & _string
    
end if
    
return _string
end pad