Thinking about file REnaming

There have been a few discussions here regarding file naming schemes, but having settled on the way I name my files (and folders), I am now thinking about workflows related to actually getting the files named properly. I am throwing out my thoughts for commentary and suggestions.

I find that I do a fair amount of renaming files once they have been created. On the surface, one might just argue to name everything according to the correct schema at the time of file creation, and I do try to do that to some extent, but I have found that I have to do a lot of renaming for a number of reasons:

  1. Files downloaded from the internet or received from others (eg via email) obviously do not follow my file naming protocol. Yes, I do use an extensive set of Hazel rules that can handle things that are regularly downloaded such as utility bills, credit card bills, and the like, but there are some of these that for various reasons Hazel cannot handle (yet) because of difficulties finding the right date in the file contents or similar reasons. Eventually I will likely solve those problems, but of course new ones will arise. Many downloads are also "one offs’ and obviously I’m not going to have a Hazel rule for those files.

  2. My file naming schema is very helpful (to me) once the files are renamed, but is unfortunately not very conducive to actual typing. My schema for most files is that the file starts with a date in YYY-MMDD format, then an underscore, and then descriptive information in the file, followed by the file extension. There are no spaces in file names; instead I use underscores, because I do enough at the command line to not want to deal with the hassle of file names with spaces. File names use only lowercase characters. In actual typing, however, it is far faster for me to type a description file name with spaces followed by a date in YYYY.MMDD format, however - it just works better on the keyboard. Sometimes, as a longtime touch typist, I just automatically capitalize things as well.

I have a utility program I wrote that can take most filenames that I have typed and intelligently convert them to the proper format, and one way that I do a lot of file renaming is to select multiple files in Finder and use a KM macro that uses my utility to generate the new file names and then rename the files. This is not a bad solution and actually works pretty well for me most of the time.

In my never-ending question to create workflows, sometimes even when there is no more efficiency to be gained, I was toying with another idea, to scan a folder and generate a BBEdit document listing the filenames. I can then type replacement file names, optionally tags to be added to the files, and then execute another script to parse the BBEdit document and do the renaming and tagging.

For example, here an off-the-cuff zsh script:


(printf "%s\n" "$1" ; find "$1" -depth 1 -exec basename {} \; | grep '^[^.].*' | \
while read LINE
	b=$(basename ${LINE})
	if [[ -d ${LINE} ]]
		n=$(echo ${b} | camelcase)
		n=$(formatfilename -d creation -l "${LINE}")
	printf "%40s --> %40s []\n" "${b}" "${n}"
done ) | bbedit

(camelcase is my utility to properly CamelCase folder names; formatfilename is my utility to build file names. The -d creation part tells it that if there is no date at the end of the filename, use the file’s creation date or content creation date in the new filename, and -l forces all characters to lowercase. There are other options to this program for different uses that I have for it.)

Taking as input a path to a folder, this script writes to a BBEdit document the folder path, and then on each line below is output of the format:
current_file_name --> suggested_file_name []

For Folders, the suggested_file_name is actually a suggested rename for the folder, as for folders I use CamelCase with no spaces (and a few quirks with dates that aren’t important here), and that’s done in the part of the script with if [[ -d ${LINE} ]].

The empty brackets are for typing tags, comma separated, to be added to the file as well, Of course, if the current and suggested file names are the same, no rename is done, and if the tags bracket is empty, no tags are added.

I haven’t written the back end script yet as I haven’t quite decided if this is the wrong way to go and/or more effort than it is worth (the script writing is minimal effort; it’s the actually usage that might not be worth the effort).

On the other hand, the idea that files are just created with whatever name is handy, including when scanning (which generates a lot of my files that need renaming later), and then I can run through all the renaming at one time for a batch of files, seems like a good way to go. By analogy, the idea of capturing ideas into OmniFocus’ Inbox and later reviewing the Inbox to create projects and tasks, or importing data in DevonThink’s Inbox and later processing into databases and folders.

I would be interested in thoughts. Is this a useful endeavor or am I heading down a road to nowhere once again?

1 Like

Check into A Better Finder Rename 11 – incorporates your idea of renaming based on an input file, as well as quite a few other approaches for renaming batches of files, and cleaning up existing folders.


I agree with @quorm, and have found ABFN to be really handy.

If you want things to just happen magically, you could use Folder Actions to trigger scripts to scan all filenames in the folder and apply some sort of fixes to them - changes spaces to underscores, etc.

Another thought is that you could use Karabiner-Elements to remap a key on your keyboard to _, and that would speed up your typing snakecase filenames. I have a Keyboard Maestro macro that types different date formats for me, ddd expands to 2020-12-23, ddh to Dec 23, 2020, ddn to 20201223, etc. (dd dash, dd human readable, dd numeric)

Finally, you could use PopClip and TextSoap to perform the filename fixes for you by selecting the filename text in Finder. (This is probably the most expensive option.)

ps. perhaps consider if the time automating this is worth the fun of doing it.

Thanks. I do have access to TextSoap through SetApp but did not think of that for this purpose. I have Karabiner Elements installed, and when in the finder, Meta-A pops up a KM menu that allows me to rename files, apply tags, etc. Either approach works fine IF the filename already contains the relevant elements; eg a relevant date and descriptive text. I’m really more looking for dealing with situations in which I need to rename the file substantively, and finding a convenient UI in which to simultaneously do that and also do file tagging.

Folder Actions would be fine but not a real advantage over Hazel which can obviously just do the same. I don’t know the overhead of having Hazel monitor my entire computer vs selected folders, although as most of the files in question wind up in one folder (“Dispatch”) for processing that might be a reasonable start.

I have Name Mangler, which is great when you have a large number of similarly named files and need to apply the same rule to each, for example when I import the images from a photo shoot, but not so much in this application.

I will have a look at A Better Finder Renamer. Maybe that will be the magic.

Nope, ABFR seems to be very similar to Name Mangler.

I may just finish up these scripts and try them out for a while to see how they work for me.

I fully respect the desire to automate things that could just as quickly be done manually, it’s a satisfying accomplishment.
I’d like to point out this simpler approach though, which I think you’ve already considered:

  • set up Hazel to check your Dispatch folder. Any file that does not start with a date in your preferred format has a date added. Any spaces are changed to underscores. If some random file gets named wonkily, change it manually. If some repeating file gets named wonkily, set up a rule.
  • set up a quick action or KM script to do the same on a file (or multiple) selected in Finder
  • I love the idea of setting something like option-space to be the underscore

Personally, and I know this may not suit everyone, I use today’s date to rename almost all my files. It gets close enough to the actual date and provides sufficient chronology for me to find things. I used to have some Hazel rules to search for dates in pdfs, but I decided they were not really helping me.

1 Like