WHAT
A perl script to (batch) view and change the type and creator of files from the terminal. You'll need the DevTools installed, as the script uses SetFile and GetFile to work.
WHY
To make open ./file work from the terminal and override the infuriating default extension-application correspondence. Please feel free to improve the script---I'm sure there's lots of room for improvement.
USE
Paste it into a file and save it (with UNIX line endings) somewhere on your PATH. I call it tc.
To view types & creators:
tc *.txt
To set types
tc -t TEXT *.txt
To set creators
tc -c ALFA *.txt
You can set types and creators simultaneously in the obvious way. Read the rest of the hint for the script...
THE SCRIPT
#!/usr/bin/perl
@files = ();
$type_ = 0;
$creator_ = 0;
$i=0;
while( $i <= $#ARGV ) {
if( $ARGV[$i] eq "-t" ) {
$type = $ARGV[$i+1];
$type_ = 1;
print " Change type to \"$type\"\n";
if( length($type) != 4 ) {
print "Type \"$type\" does not have length 4. Try using quotes if you need spaces.\n";
$i = $#ARGV;
}
$i = $i+2;
}
elsif ( $ARGV[$i] eq "-c" ) {
$creator = $ARGV[$i+1];
$creator_ = 1;
print "Change creator to \"$creator\"\n";
if( length($type) != 4 ) {
print "Creator \"$creator\" does not have length 4. Try using quotes if you need spaces.\n";
$i = $#ARGV;
}
$i = $i+2;
}
else {
push(@files, $ARGV[$i]);
$i++;
}
}
foreach $file (@files) {
if( $type_ == 1 ) {
`SetFile -t '$type' '$file'`;
}
if( $creator_ == 1 ) {
`SetFile -c '$creator' '$file'`;
}
$newtype = `GetFileInfo -t '$file'`;
chomp($newtype);
$newcreator = `GetFileInfo -c '$file'`;
chomp($newcreator);
print "$newtype $newcreator $file\n";
}
if( $i == 0 ) {
print " usage: tc [-t TYPE] [-c TYPE] filenames\n";
print " if type and creator are present then they will be set for the files\n";
print " otherwise the type and creator of the files are displayed\n";
}
QUESTION
BTW: Does anybody know how to change the default extension-application correspondence?
Mac OS X Hints
http://hints.macworld.com/article.php?story=20031128124513712