#!perl =pod Code submission from: Joshua Gemmell (joshua@helix.net) "Mog" is a droplet that will change a file's (or a group of files') creator and type. Handy for when you have a bunch of plain text files that you want to be made MacPerl text files, etc. Save it as a droplet and you can either drag and drop files & folders onto it or double-click it to prompt you for files. It's good for what ails you and can fit snugly into any pocket! =cut ########################################################################### # Mog - Change any file(s) to other files # Well... all it _really_ does is change the type/creator # # NOTE: if you didn't save this as a droplet, you are, like, TOTALLY # missing out! # # ACTIONS: # DRAG&DROP - files & folders (not recursive) # DOUBLECLICK - open file box, repeat ad lib 'til fade # # Written by Joshua Gemmell in the fall of 1997 (joshua@helix.net) while # working at Open Learning Agency (joshg@ola.bc.ca) # This code is free for you to use and distribute, so long as you are a # good little boy or girl. Anything that goes wrong in any way while # you are using this (or a derivative) is your own bloody fault. # Any complaints send email to kevinm@ola.bc.ca - ha ha just kidding! ########################################################################### use subs qw(UnFold Transmogrify); ########################################################################### # I just thought I'd throw these in here so you could decide what you'd # like to change the dropped files to on the fly. As well, just # add another "flavour" to the hash and you're set! # If you want to bypass this "Pick" section, comment it out and read # the next set of instructions ########################################################################### %Flavours = ( 'MacPerl TEXT' => [("McPL", "TEXT")], 'BBEdit' => [("R*ch", "TEXT")], 'MachTen' => [("MUMM", "BINA")], 'Animated GIF' => [("gfBr", "GIFf")], 'GraphicConverter GIF' => [("GKON", "GIFf")], 'MacPerl DROPLET' => [("MrPL", "APPL")], 'MacGzip Gzip' => [("Gzip", "Gzip")], 'Stuffit SIT' => [("SIT!", "SITD")], ); # # use MacPerl::Pick to pick the new creator/type (if "cancel", exit) # returned value of $pik is the desired %Flavours{ key } # unless ($pik = MacPerl::Pick("Whatcha want?", sort keys %Flavours)) { exit(0) } ($creator, $type) = @{$Flavours{$pik}}; ########################################################################### # If you only ever change files to one type/creator, comment out the # above block of code and uncomment this next line. Keep in mind # you may also want to change the values! # IE: if you only use Mog to change plain text to MacPerl, use this: ########################################################################### #($creator, $type) = ("McPL", "TEXT"); # # check and see if something was drugged and dropped # if (@ARGV) { # # if there was, make a list of all files that can and will be Mog'd # @List = (); foreach $Item (@ARGV) { if(-d $Item) {UnFold $Item . ":"} # pull files out of folders if(-f $Item) {push(@List, $Item)} # these are fine as they are } # # then... change 'em up, boys! # foreach $file (@List) { Transmogrify $file; } } else { # # they didn't drag and drop! but that's ok... # prompt for a file and keep looping until they press CANCEL # while(1) { if($file = StandardFile::GetFile()) { Transmogrify $file; } else { last; } } } exit(0); # # Transmogrify - get a file, change the creator & type # sub Transmogrify { my($File) = shift; MacPerl::SetFileInfo($creator,$type,$File); } # # UnFold - pull files out of folders # sub UnFold { my($Dir) = shift; opendir(DIR, $Dir) or return 0; @DirFiles = readdir(DIR); closedir(DIR); foreach $File (@DirFiles) { if(-f $Dir.$File) {push(@List, $Dir.$File)} } }