Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

System Report will display the system's Hardware UUID in the format 01234567-89ab-cdef-0123-456789abcdef.

Using the shell we can retrieve the same UUID:

ioreg -rd1 -c IOPlatformExpertDevice | grep -E '(UUID)'

Is it possible to get this UUID in Python without resorting to executing a shell command?

share|improve this question
    
Programming questions are off-topic here. Try StackOverflow instead. –  Gerry Nov 23 '12 at 4:35
add comment

1 Answer 1

up vote 1 down vote accepted

Short answer: not really.

Long answer: sort of, but it's probably more trouble than it's worth, unless you really can't used the shell command for some reason. OS X doesn't really expose much system configuration to Python. Most scriptable interfaces to configure OS X are shell-based or AppleScript-based (and of course the various Objective-C APIs).

Getting the UUID is possible in AppleScript:

tell application "System Information"
    set profile to system profile
    quit
end tell

set delim to AppleScript's text item delimiters
set AppleScript's text item delimiters to "Hardware UUID: "
set uuid to paragraph 1 of text item 2 of profile
set AppleScript's text item delimiters to delim
uuid

But as you can see, it's a bit convoluted (and is much slower than the ioreg method, as it has to process the entire system profile).

There is a way to bridge AppleScript to Python, known as Appscript, but it's no longer developed, and not recommended for new projects. However, if you're really determined, you could convert the above AppleScript into Python using Appscript. But to be honest, it seems like a lot of trouble to get a worse result.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.