-- Date in Filename
-- https://c-command.com/scripts/eaglefiler/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-05-24



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