I am running MATLAB code on two different computers, both with the same username.

I would like to distinguish between the two Macs by having the code identify that one system is a desktop, and the other a laptop.

Is there a Terminal command that will print the type of computer I am using (so I can implement the relevant function?)


This command should work for you:

sysctl hw.model

This will return the Model Identifier for your machine. The below is an example for a mid-2012 Retina MacBook Pro:

Machine123:~ username$ sysctl hw.model
hw.model: MacBookPro10,1

Below are some references on Apple's site that describe Model Identifiers - there doesn't seem to be a single reference:

MacBook Pro Model Identifiers

MacBook Model Identifiers

MacBook Air Model Identifiers

iMac Model Identifers

Mac Pro Model Identifiers

Mac Mini Model Identifiers

  • 1
    This'll give you one of Apple's machine-readable strings, same as in System Information -> Hardware -> Overview -> Model Identifier. If you want to reliably distinguish between desktops and laptops, you'll need to maintain a current and exhaustive list of Apple's model-ID prefixes (PowerBook, MacBook, MacBookAir, MacBookPro vs. PowerMac, iMac, Macmini, MacPro). Oct 27 '15 at 6:58
  • @BlacklightShining You should edit that information into the answer
    – mmmmmm
    Oct 27 '15 at 12:04
  • @Mark No, Scot should edit that information into the answer. The edit would add meaning, rather than just clarifying. Oct 27 '15 at 12:54
  • 1
    @BlacklightShining If you can improve the answer by editing an answer, please do so. This is how the site works.
    – nohillside
    Oct 27 '15 at 13:54
  • Perfect answer!
    – voices
    Oct 27 '15 at 21:12

Simply check if your Mac contains a battery, a smart battery manager or a clamshell mode to distinguish between laptop and desktop.

Check the output of ioreg -l > ~/Desktop/ioreg.txt for proper strings.

E.g. on Lion (10.7.5) and probably newer operating systems you can use:

ioreg -l | grep SMB0

(SMB0 probably means SMartBattery)


ioreg -l | grep AppleClamshellCausesSleep

On a desktop you get no output and on a laptop you get an output similar to this:

    | +-o SMB0  <class IOACPIPlatformDevice, id 0x100000166, registered, matched, active, busy 0 (35 ms), retain 9>


    | | |   "AppleClamshellCausesSleep" = Yes

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .