[MacRuby-devel] Computer Serial Number

Terry Moore tvmoore at mac.com
Tue Apr 5 14:43:04 PDT 2011

There is no BridgeSupport for IOkit... so ruby is out for now.

like Henry said you can escape to a shell.. or wrap this snippet in an objc class...

#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>

// Returns the serial number as a CFString.
// It is the caller's responsibility to release the returned CFString when done with it.
void CopySerialNumber(CFStringRef *serialNumber)
    if (serialNumber != NULL) {
        *serialNumber = NULL;

        io_service_t    platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault,

        if (platformExpert) {
            CFTypeRef serialNumberAsCFString =
                                                kCFAllocatorDefault, 0);
            if (serialNumberAsCFString) {
                *serialNumber = serialNumberAsCFString;

Quote form MacRuby Dev 17/1/2011
"Looks like I talked too fast, there isn't any BridgeSupport file for IOKit, 
even in Preview 2. I will look into it, as I'm planning to roll out a new 
version soon.

On 6/04/2011, at 9:26 AM, Henry Maddocks wrote:

> On 6/04/2011, at 9:10 AM, Robert Rice wrote:
>> Hi Gang:
>> Could anyone help me to read the computer's serial number from a MacRuby program. Since I don't know Objective C, I haven't been able to figure out how to access it.
> system_profile = `system_profiler SPHardwareDataType`
> serial_number = system_profile.match(/Serial Number.*: (.*)/)[1]
> Henry
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20110406/ddebb210/attachment.html>

More information about the MacRuby-devel mailing list