Skip to content

Instantly share code, notes, and snippets.

@rustymyers
Forked from acidprime/getguid.pl
Created January 18, 2012 15:32
Show Gist options
  • Save rustymyers/1633550 to your computer and use it in GitHub Desktop.
Save rustymyers/1633550 to your computer and use it in GitHub Desktop.
Using perl to parse plist data from dscl snippet, example using GeneratedUID
#!/usr/bin/perl
use Foundation;
my $NSASCIIStringEncoding = 1;
my $dscl = "/usr/bin/dscl";
sub getGeneratedUID(){
$name = shift;
my $command = "$dscl -plist . -read /Users/$name GeneratedUID";
print "$command\n";
my $output = `$command`;
my $plist = NSString->alloc()->initWithCString_encoding_($output,$NSASCIIStringEncoding);
my $data = $plist->dataUsingEncoding_($NSASCIIStringEncoding);
my $record = NSPropertyListSerialization->propertyListWithData_options_format_error_($data,NSPropertyListImmutable,0,0);
my $array = $record->objectForKey_('dsAttrTypeStandard:GeneratedUID');
return $array->objectAtIndex_(0)->description()->UTF8String();
}
my $logname = $ENV{'LOGNAME'};
my $guid = &getGeneratedUID($logname);
print "GeneratedUID: $guid\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment