How to automatically rename (add extension) upon creation of a file?

Hi everyone!

I would like to make a script that automatically adds an extension to a file (i.e. renames it) upon creation of said file. Ideally, I’d like Finder to watch a specified folder, and then jump into action and automatically rename the file once it exists. Is this possible? I want it to turn FILE into FILE.CSV if FILE anytime and every time exists. The result will be that FILE will always be transformed into FILE.CSV without me noticing or having to do anything else. (Actually, I guess FILE.CSV needs to replace FILE since FILE will already exist (from a previous export of the data.)

(My situation is that I have MYOB Accountedge which exports CSV files, but stupidly, doesn’t append the .CSV extension. When I open the file in my label maker software (Brother P-Touch Editor), the software decides to duplicate the old file and adds “.CSV” to this new file. However, this means that the label maker will always work from an out-of-date file, since the file it creates is not linked to the file I regularly export from Accountedge!)
i.e. in Accountedge - export ‘Items’ → Accountedge creates “FILE”
P-Touch - open “FILE”
P-Touch creates a duplicate of “FILE” and calls it “FILE.CSV” and works from “FILE.CSV”
Thus, whenever new data is exported to “FILE”, P-Touch has no idea about the new data, because it is working from its own outdated “FILE.CSV”)

THANKS SO MUCH!!!

-Danny

One thing you might consider instead of using AppleScript is to add the .csv extension to the file name when creating it from MYOB. I just tried it and the extension stays.

If you still want to use AS to watch the folder I suggest using a launchd agent. StefanK has a good way of creating one and you can find it in CodeExchange.

Also, there are lots of posts on changing a files name. Many approaches you will find when you search MacScripter.

If you run into any problems post the code you are having issues with.