Created
January 11, 2012 23:28
-
-
Save acidprime/1597440 to your computer and use it in GitHub Desktop.
Using perl to parse plist data from dscl snippet, example using GeneratedUID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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