Use JavaScript for Automation to rename files in batch!
While working on some client-side code at Oozou, I often have to rename a lot of image files.
For example, Bourbon uses _2x.png
for retina images, rather than @2x.png
used by Retina.js.
I used to do this manually, until I am fed up and write this script.
I'm not sure who wrote this script, but I first want to thank him/her for sharing. Much appreciated.
To deal with the issue above (you can expect a lot of JXA newbees), may I suggest:
(1) Add a section in the header comments for "How to Use"
(2) ADD a user selection validation test, and alert the user if no files have been selected in the Finder, and advise him/her that is required before running the script.
(3) You could also run the chooseFile method if the user does not make and Finder selections:
chooseFile
[withPrompt: text] : the prompt to be displayed in the dialog box
[ofType: list of text] : a list of file types or type identifiers. Only files of the specified types will be selectable.
[defaultLocation: alias] : the default file location
[invisibles: boolean] : Show invisible files and folders? (default is false)
[multipleSelectionsAllowed: boolean] : Allow multiple items to be selected? (default is false)
[showingPackageContents: boolean] : Show the contents of packages? (Packages will be treated as folders. Default is false.)
→ alias : the chosen file