C-Command Software Forum

File name automation

I store physical files with the filename format YYMMDD-Title.

It is such a pain having to enter a record’s title and creation date, then enter it all over again in the filename.

Would be great of there was an option for EF to do this automatically, per Mekentosj Pages etc.

Meanwhile, I know nothing of scripting, but is this the kind of thing you can get scripts to do?

You can use the Date in Filename script to add the date to the filenames of the selected records.

Also, you could use a stationery script to automatically add the date when creating a new file in EagleFiler.

Almost works. Modifies the filename as expected. But the first time through the script, the script also modifies the “Title” with _newName as well as the filename, even though the script doesn’t set the “title” parameter. If I correct the title by hand then rerun the script, it works.

I have no idea what is going on.

It seems to be working as expected for me. Could you give a specific example your title and filename before and after running the script?

I’m running this script, where I’ve switched the date around (but I noticed it doing it with the script exactly as I downloaded it from your site)

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 creation date)
            set _newName to _dateString & "-" & _base
            set filename of _record to _newName
        end repeat
    end tell
end tell

on dateStringFromDate(_date) -- YYMMDD
    set _shortyear to (text items 3 thru 4 of (year of _date as string)) 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 _shortyear & _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

Before:

Date = “21/06/2008”
Title = “School Report”
Filename = “School Report.pdf”

After:

Date = “21/06/2008”
Title = “080621-School Report”
Filename = “080621-School Report.pdf”

If I manually correct the title, i.e. set Title = “School Report” and re-run it, the script functions. It is random. Sometimes it works and only renames Filename, sometimes it renames Title.

If the title and the filename start out the same, EagleFiler automatically propagates filename changes to the title so that they stay in sync. (This happens when manually renaming a file, not just with AppleScript.) If you don’t want it to do this, you could add a line to the end of the repeat such as:

set _record's title to _base

Works great now - thanks. The working script to create the filename

YYMMDD-Title

from the file’s title and creation date, for anyone that wants to adopt my peculiar filing convention :slight_smile:

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 creation date)
            set _newName to _dateString & "-" & _base
            set filename of _record to _newName
            set _record's title to _base
        end repeat
    end tell
end tell

on dateStringFromDate(_date) -- YYMMDD
    set _shortyear to (text items 3 thru 4 of (year of _date as string)) 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 _shortyear & _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