Friday, July 11, 2003

Automatically renaming multiple files in OSX

Category: Mac, Category: iView Media Pro, Category: AppleScript

Originally posted on my iBlog 11 July 2003.

If they are image files, iViewMedia Pro does this nicely with its Batch Rename function. However, iView will only deal with files of types it can display (most image types, including pdf files).

OSX has an AppleScript that also does this nicely, although it took me a while to figure out how to get this set up.

First, the Script Menu needs to be in the Finder. To do this (if it is not there already), go to Applications:AppleScript and double-click on "Script Menu.menu." This will add the Script Menu to the Finder. (Not surprisingly, the Mac Help did not tell me how to do this when I looked.)

There are several scripts accessible from the Script Menu that rename files, all found in the Finder Scripts folder of the Script Menu. I wanted to rename all postscript files from MS Word, ending in ".doc.ps" to just ".ps" before converting them to pdfs. The script to do this is called "Replace text in item names." The big trick in using this script is that it will only work on items in the front-most window. That means that if you have a Finder Window in the list view, it will only apply to files and/or folders (you select) that are in the uppermost level of the list hierarchy. It is easiest to stay in the Icon view.



Before I figured this out, I explored how to do it do in the Terminal. There is no default way. The appropriate command for renaming files is "mv" (e.g., mv oldfilename newfilename). But after many attempts, I learned on the web that mv does not handle wildcard filenames. To get around this in UNIX, you have to write a little program (see below).

Source URL: http://www.ucc.ie/doc/World-Wide_Web/htmlfaq.html

How do I rename all the files from .htm to .html after copying them from a PC to a UNIX machine?

UNIX's mv (`move') command won't handle wildcard filenames. However, there's a program called htmaddl (for `HTM-add-"L"'), so you can login and type htmaddl . This will rename all .htm files to .html

If you haven't got this program on your UNIX machine, you can type it into a file called htmaddl :
#! /bin/sh

for f in *.htm; do
base=`basename $f .htm`
mv $f $base.html
done

After saving it and exiting your editor, make it executable by typing the command
chmod ugo+x htmaddl

Best of all, move it into your ~/bin directory, or ask your WebMeister to put it in /usr/local/bin so everyone can use it.

0 Comments:

Post a Comment

<< Home