«From a request on the Mac Scripting list... |
| «I'm looking for something that would allow me rename files based on a pattern |
| «matching scheme. For example, I want to rename the files |
| «H001-001.tngif, H001-002.tngif, H001-003.tngif,... |
| «to H001001.gif, H001002.gif, H001003.gif,... |
| «Add a call to this script to the Finder's menu bar, at system.menubars.MACS. |
| «In the Finder, select the folder you want to operate on. |
| «And choose the command from the Finder's menu bar. |
for folder in FinderMenu.getSelectionList () |
| if not file.isFolder (folder) |
| fileloop (f in folder, infinity) |
| fname = file.fileFromPath (f) |
| suffix = string.nthField (fname, '.', 2) |
| local (namepart = string.nthField (fname, '.', 1)) |
| namepart = string.replaceAll (namepart, "-", "1") |
| file.rename (f, namepart + ".gif") |