Edit AllPages

Here is a script that parses an Info.plist file and outputs the XML code needed to export those UTIs that the system does not know about. It uses the ListAllDeclaredTypeIdentifiers program to find out which UTIs are already declared on your system. It is a bit hackish, but it can save you a lot of work if you declare a whole lot of new types. It relies on the Info.plist being indented with tabs in the same way that Xcode does!

It takes the path to an Info.plist file as an argument, and optionally you can list any UTIs you want to conform to.

– WAHa


use strict;

my $lstypes_command=”./lstypes”; my @definedtypes=grep $_,split /\n/,$lstypes_command;

die “Usage: Info.plist [types-to-conform-to …]” unless @ARGV>=1;

my $plist; open PLIST,$ARGV[0] or die “Couldn’t open file "$ARGV[0]"”; $plist.=$_ while();

my $conform; $conform=”\t\t\t\n".(join "",map "\t\t\t\t$_\n",@ARGV[1..$#ARGV])."\t\t\t” if(@ARGV>1);

my $declaredtypes; $plist=~m!UTExportedTypeDeclarations\s^(\t)\s*^(.*?)^\1!sm; $declaredtypes.=$2; $plist=~m!UTImportedTypeDeclarations\s^(\t)\s*^(.*?)^\1!sm; $declaredtypes.=$2;

@definedtypes=grep $_ ne $1,@definedtypes while($declaredtypes=~m!UTTypeIdentifier\s*(.*?)!msg);

$plist=~m!CFBundleDocumentTypes\s^(\t)\s*^(.*?)^\1!sm; my $types=$2;

my %types; while($types=~m!^(\t)\s*^(.*?)^\1!msg) { my %type; my $typedef=$2; $type{$1}=$2 while($typedef=~m!(.*?)\s^(\s<(\w+)>.?</\3>|\s*<\w+/>)!msg);

my ($id)=$type{LSItemContentTypes}=~m!<string>(.*?)</string>!;

$types{$id}=\%type if $id and !grep $id eq $_,@definedtypes; }

print “\t\n";

for(sort keys %types) { my $type=$types{$_}; print “\t\t\n";

print "\t\t\t<key>UTTypeIdentifier</key>\n";
print "\t\t\t<string>$_</string>\n";

	print "\t\t\t<key>UTTypeDescription</key>\n";
	print "$$type{CFBundleTypeName}\n";

	print "\t\t\t<key>UTTypeConformsTo</key>\n";
	print "$conform\n";

	print "\t\t\t<key>UTTypeIconFile</key>\n";
	print "$$type{CFBundleTypeIconFile}\n";

print "\t\t\t<key>UTTypeTagSpecification</key>\n";
print "\t\t\t<dict>\n";

    	print "\t\t\t\t<key>public.filename-extension</key>\n";
	print "$$type{CFBundleTypeExtensions}\n";

    	print "\t\t\t\t<key>public.mime-type</key>\n";
	print "$$type{CFBundleTypeMIMETypes}\n";

    	print "\t\t\t\t<key></key>\n";
	print "$$type{CFBundleTypeOSTypes}\n";

print "\t\t\t</dict>\n";
print "\t\t</dict>\n"; } print "\t</array>\n";