Since starting to get back into automation and setting up workflows I wonder how I might best do this.
I work in Numbers a lot and export to CVS files. This will place a folder on my desktop with all the various sheets included. Numbers adds “Table 1” to each of the sheets, so I get a folder with my file name (the folder name changes each time, and takes the name from the Numbers Doc), and inside I get files names such as:
What I would like to do is have a Hazel rule to strip away the “-Table 1” from each of the file names. I can’t figure out how to get hazel to do this. I know how to make it “watch” the desktop for a folder. And I see there is a Run Rules on Folder Contents action. But nothing I try can get it to work.
that is exactly what I tried, but it doesn’t work as the files are contained in a folder. That folder is aways a different name, so I can’t search on folder name. I also tried to make the Kind a Folder for the first step, but that doesn’t do it either.
You need two rules, both attached to your desktop folder. One rule is just a rule that looks for folders and does the “Run rules on folder contents” action.
@ChrisUpchurch has a great start for you here but there’s one problem and a limitation: the rules specified won’t match if you’ve got a space or other special character in the text before the -Table and you’ll need to add an exception for each -Table (number).
To make this a little more robust, you can extract the ‘True File Name’ and use that in your actions to rename the file (rather than just replacing the offending bits).
Conditions
For your conditions, start with an Extension: is with csv so you don’t accidentially get another file, however unlikely it may be.
Then keep the Name: matches rule, and drag in a custom text• token. You can name it (I called it True File Name) and tell it to look for anything. Then in the main pattern, add -Table and drag in a Number [123] token. You can see this below:
Thanks - that is great. May I ask how this works? The True File Name token includes anything, which I assume would include the entire file name. So once I add the “-Table” and number token, that removes that info from the True Name token (so in this case, it makes the variable become what ever is in front of -Table)?
Yes, you understand correctly. True File Name’s anything token will gobble up everything up to the point it meets ‘-Table [number]’, even if it were Cheese and Card-Table-Table 75.csv to get Cheese and Card-Table.
You could certainly do this, but you might want to adjust it depending on what your desired outcome is. But speaking hypothetically, yes, it’s definitely possible.