I was handed an Excel spreadsheet of 40 or so Apple serial numbers and asked "can we put Mavericks on these?"
I assumed it would be enough to find an algorithm that takes a serial number and tells me what model the computer was. I wanted to get some practice writing
what-mac takes a serial number and returns a JSON object with information about the model and size.
It turns out there isn't an easy way to work out the model based on the serial, however I found a StackExchange answer that described an XML API available from Apple's website. Hit
support-sp.apple.com/sp/product?cc=XXXX (where XXXX is the last 3 or 4 digits of the serial) and it will return something like:
<?xml version="1.0" encoding="utf-8" ?> <root> <name>CPU Name</name> <configCode></configCode> <locale>en_US</locale> </root>
request, to make an HTTP request to the API, and
xml2js, to parse the returned XML, I was nearly there. The trickiest part was parsing the configuration code into something usable. I wanted to have each segment (year, size, type) broken up into an object property. To do that I wrote some ugly regexs and did a little string splitting to break it up. Even with my weak string parsing skills I was able to successfully break down each Mac that I have been able to test. Have any that don't work? Open an issue!
If you have a serial you want to test you can install the module and run it like so.
npm install -g what-mac ... echo "XXXXXXXXXDV33" | what-mac.js