Skip to content

Instantly share code, notes, and snippets.

@tluyben
Created June 13, 2013 10:38
Show Gist options
  • Save tluyben/5772788 to your computer and use it in GitHub Desktop.
Save tluyben/5772788 to your computer and use it in GitHub Desktop.
Convert a CSV to Apple iOS import plist format. The format in the samples from Apple is not complete and thus does not work. This one does (at least it does now).
#!/usr/bin/perl
$file = $ARGV[0];
$skip = $ARGV[1];
$prefix = $ARGV[2];
if (!$file or not -f $file) {
print "Usage: ./csv2deviceids.pl filename.csv [skip first n lines] [prefix]\n";
exit;
}
$skip = 0 if !$skip;
$prefix = "" if !$prefix;
$c = 0;
print qq~<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Device UDIDs</key>
<array>
~;
open(F1, $file);
while(<F1>) {
chomp;
if ($c >= $skip) {
my @l = split(/,/, $_);
# first empty = empty line
next if !$l[0];
# you can stuff whatever in the rest of the field, we'll find the udid, for instance, we
# put the company name, role of the person, device type etc in there
my $udid = 0;
foreach(@l) {
if (length($_)==40 and /(\w+)/) {
$udid = $_;
last;
}
}
next if !$udid;
my $name = $l[0];
$name = $prefix." ".$name;
$name =~ s/[^\w]//isgm;
print qq~ <dict>
<key>deviceNumber</key>
<string>1</string>
<key>deviceIdentifier</key>
<string>$udid</string>
<key>deviceName</key>
<string>$name</string>
</dict>
~;
}
$c++;
}
close F1;
print qq~
</array>
</dict>
</plist>
~;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment