iPhone 2 4-Mar-2010 4:38 PM
Edit FancyEdit New New Blog Upload All Recent Home Logout

#! /usr/bin/perl # # WARNING: USE AT YOUR OWN RISK!!!!!!! <-- see the exclamation points? #

# Require a replacement id
if (!(@ARGV)) { die "Please supply a replacement for com.yourcompany\n"; } 
print "About to replace com.yourcompany with $ARGV[0]\n";

# copy folder to desktop
my $doit = qq{cp -r '/Developer32/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/Application' ~/Desktop};
`$doit`;

# Iterate through each folder
my $TEMPLATEDIR = "~/Desktop/Application";
my $doit = qq{ls $TEMPLATEDIR};
foreach my $folder (split('\n', `$doit`))
{
    # Iterate through each match
    $doit = qq{grep -iR com.yourcompany $TEMPLATEDIR/*};
    foreach my $match (split('\n', `$doit`))
    {
    $match =~ s/:.*//;
        print `cat '$match' | sed 's/com.yourcompany/$ARGV[0]/' > '$match.delt'`;
        `mv '$match.delt' '$match'`;
    }
}

# Move the patched folder into place
my $DESTDIR = "~/Library/Application Support/Developer/Shared/Xcode/Project Templates";
print "Move folder into ", $DESTDIR, "\n";
#`mkdir -p '$DESTDIR'`;
# `rm -rf $DESTDIR/Application`;
# `mv ~/Desktop/Application $DESTDIR`;