Enforcing file naming conventions

Hi,

I have this weird self-imposed rule to have the imported files following a specific naming convention:

<date>-<filename>-xtag] xtag]*.extension

where:

<date>: is a 14 digit date (yearmonthdayhourminutesecond)
<xtag>s are a small set of special tags I’m using

Most of the time importing things into EF happens through my own script (which basically sends the import to 2 different tools, one being EF). In this case I control the process and the imported file follows my naming convention.

But starting a couple of days ago I was thinking to try to use EF for a second use case and that would rely mostly on the default EF import functions. Now I’m wondering if there’s a way to impose these naming conventions when using EF default import functionality. My initial thought was to involve an external tool like Folder actions/Hazel to do the naming part, but:

  1. this would break EF as it would involve renaming files [1]
  2. I’m not sure yet how easy it would be to access the tags (I know they are actually attached to the file[2])

Thanks in advance for any suggestions,

A://

[1]: as per http://c-command.com/eaglefiler/manual-ah/library-folders
[2]: mdls shows them as mKDItemOMUserTags and kOMUserTags attributes

It’s not clear to me what the relation is between the [xtag]s and the tags in EagleFiler. Secondly, although it’s not a good idea to rename files out from under EagleFiler, you can use AppleScript to tell EagleFiler to rename the files (and also to see which tags are assigned to them).

At some point I’ll try to explain my system, but it would take me quite a bit of explaining what I want to accomplish. Once I’ll have this written down, I’ll post about it. Very shortly put, I’m trying to create a long-term archival system based on EF, but that could outlive EF (e.g. in case I’m forced to other OS or EF stops working, etc.)

You are as always right (and I’ve forgotten I already have some EF scripts doing something in this direction). The only remaining bit to completely figure this out are:

  1. at the time the file is written on disk is it safe to trigger a script that would lead to modifying the file name? Or should there be a delay?
  2. is there a way to retrieve an EF record based on the file name? I assume it should be something using the library record basename but I have to confess I don’t know how to select that in a script without having to iterate over all records :-(.

tia,

A://

What matters is whether EagleFiler has imported the file. If you’re importing via script, you can do something like this:

tell application "EagleFiler"
    tell library document 1
        set {_record} to import files {POSIX file _path}
        -- A
    end tell
end tell

When it gets to A, the file has been completely imported, and you have a reference to it in _record.

If the import is happening indirectly, by moving the file into EagleFiler’s library folder, you would need to use the scan for new files script command to tell EagleFiler to look for it, and then you’d have to know the name of the file in order to get the AppleScript library record object for it.

Here are some ways to do it:

tell application "EagleFiler"
    tell library document 1
        -- Search whole library, assuming filename is unique
        set _record to first library record whose filename is "Foo.txt"
        
        -- Search directly inside top-level folder Bar
        set _folder to library record "Bar" of root folder
        set _record to first library record of _folder whose filename is "Foo.txt"
    end tell
end tell

Firstly thanks for the quick response. Actually the most interesting scenario would be the “default” one where an import happens using EF capturing shortcuts or bookmarklets. These trigger an import on EF that results in writing a file down on disk. If I have a Folder Action/Hazel rule watching for newly created files that match a specific criteria (e.g. the filename doesn’t start with 14 digits) would it be same to trigger an AppleScript at that time, or is EF still processing the file even if it was written to disk.

I am very aware that I might be forcing my luck with EF, but I had to ask it :-).

A://

It’s safe, but there is a small window of time in which the file will be there but it won’t yet be recorded in EagleFiler’s database. I think you could just write your script so that if the record with the expected name isn’t found, wait a few seconds and try again.