Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find Mac OSX serial number

How to find the Mac OSX serial number.

Sometimes it is required to get serial number of a mac, and you validate on that.

I needed the same, few years back, when I developed a plugin for OsiriX. I was asked to release it in such a way, only few systems can use that plugin.

If we get any better solution than this, that will be quite helpful for all of us.

like image 619
Anoop Vaidya Avatar asked Mar 16 '13 15:03

Anoop Vaidya


People also ask

How do I find my osx serial number?

In About This MacFrom the Apple menu  in the corner of your screen, choose About This Mac. You should see an overview of your Mac, including its model name and serial number.

How do I find my Mac serial number without turning it on?

If your computer is turned off or won't turn on, you can flip your Mac over and find the serial number physically printed on the hardware. Look for the text beginning with "Designed by Apple in California," and then look at the lowest line of writing, where you'll find the serial number.

Can Mac be found by serial number?

Unfortunately, despite there being some misleading information online, it is NOT possible to track your Mac using the serial number alone – your Mac MUST have 'Find my Mac' switched on, or you must be using an active tracking app.

How do I find my Apple serial number from terminal?

Use a Mac Terminal Command To find your serial number using this method, open Terminal from the Applications folder or typing Terminal in Spotlight. Next, input the following command “system_profiler SPHardwareDataType | grep Serial” and press the Enter key. Your serial number should appear on the succeeding line.


1 Answers

The following code is mainly copied from Technical Note TN1103, with small modifications to return an NSString and to make it compile with ARC:

#include <IOKit/IOKitLib.h>

- (NSString *)getSerialNumber
{
    NSString *serial = nil;
    io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault,
                                     IOServiceMatching("IOPlatformExpertDevice"));
    if (platformExpert) {
        CFTypeRef serialNumberAsCFString =
        IORegistryEntryCreateCFProperty(platformExpert,
                                        CFSTR(kIOPlatformSerialNumberKey),
                                        kCFAllocatorDefault, 0);
        if (serialNumberAsCFString) {
            serial = CFBridgingRelease(serialNumberAsCFString);
        }

        IOObjectRelease(platformExpert);
    }
    return serial;
}

You have to add the IOKit.framework to your build settings.

like image 115
Martin R Avatar answered Oct 06 '22 00:10

Martin R