Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

arletr

macrumors newbie
Original poster
Jul 27, 2022
7
0
I am trying to find out the model year of any MacBook with a command line in terminal.

For example (MacBook Pro (14-inch, 2021)
 

arletr

macrumors newbie
Original poster
Jul 27, 2022
7
0
Code:
system_profiler SPHardwareDataType
Screen Shot 2022-07-27 at 3.42.57 PM.png

This is what I get. I am looking to get something like this:
Screen Shot 2022-07-27 at 3.43.45 PM.png
 

NoBoMac

Moderator
Staff member
Jul 1, 2014
6,246
4,936
^^Kewl!

From that thread, looks like the following is pretty straight forward/easy. Not quite what About This Mac returns, but close enough imo. Returned exactly what is in About this Mac for me.

Code:
defaults read ~/Library/Preferences/com.apple.SystemProfiler.plist 'CPU Names' | cut -sd '"' -f 4 | uniq
 
  • Like
Reactions: frou and bogdanw

BanditoB

macrumors 6502
Feb 24, 2009
482
258
Chicago, IL
@NoBoMac - the code you provided returns "MacBook Pro (13-inch, M1, 2020)" on my 2022 M2 MacBook Air, so it doesn't seem reliable.

The code from @arletr gave the correct information, but doesn't show the year.
 

bogdanw

macrumors 603
Mar 10, 2009
6,099
3,013
@NoBoMac - the code you provided returns "MacBook Pro (13-inch, M1, 2020)" on my 2022 M2 MacBook Air, so it doesn't seem reliable.
You should probably consider reinstalling macOS, as the current installed one doesn’t properly recognize your MacBook.
 

arletr

macrumors newbie
Original poster
Jul 27, 2022
7
0
^^Kewl!

From that thread, looks like the following is pretty straight forward/easy. Not quite what About This Mac returns, but close enough imo. Returned exactly what is in About this Mac for me.

Code:
defaults read ~/Library/Preferences/com.apple.SystemProfiler.plist 'CPU Names' | cut -sd '"' -f 4 | uniq
this is what it outputs for me:
Screen Shot 2022-07-28 at 11.24.53 AM.png



This is what it outputs for my coworker:

Screen Shot 2022-07-28 at 11.29.42 AM.png



I have an M1, he does not. How can we tweak the script for M1?
 

chrfr

macrumors G5
Jul 11, 2009
13,703
7,267
this is what it outputs for me:
View attachment 2035625


This is what it outputs for my coworker:

View attachment 2035630


I have an M1, he does not. How can we tweak the script for M1?
The command works fine on all Macs, but only if System Profiler has been run in the GUI, on that particular computer. Running system_profiler at the command line will not generate that preference file. It'd seem like there's a chance the file will have the wrong data if Migration Assistant was used and System Profiler hasn't been run on the current system.
 
Last edited:
  • Like
Reactions: NoBoMac

arletr

macrumors newbie
Original poster
Jul 27, 2022
7
0
The command works fine on all Macs, but only if System Profiler has been run in the GUI, on that particular computer. Running system_profiler at the command line will not generate that preference file. It'd seem like there's a chance the file will have the wrong data if Migration Assistant was used and System Profiler hasn't been run on the current system.
Can you show me how to do that? thanks so much
 

chrfr

macrumors G5
Jul 11, 2009
13,703
7,267
Can you show me how to do that? thanks so much
Show you how to do what? You'd have to have opened up the System Report app in the GUI for the preference file referenced in that command to exist.
 

arletr

macrumors newbie
Original poster
Jul 27, 2022
7
0
Show you how to do what? You'd have to have opened up the System Report app in the GUI for the preference file referenced in that command to exist.
i guess how to open that in GUI. I'm new to this so its a bit confusing.
 

chrfr

macrumors G5
Jul 11, 2009
13,703
7,267
i guess how to open that in GUI. I'm new to this so its a bit confusing.
Hold the option key, click on the Apple menu, select the first item, "System information..." or go to the Apple menu, choose "About this Mac" and then click System Report.
This command, as written, also requires that you're running it as the logged in user, so if you're trying to get this info remotely it's also potentially going to fail.
 

arletr

macrumors newbie
Original poster
Jul 27, 2022
7
0
Hold the option key, click on the Apple menu, select the first item, "System information..." or go to the Apple menu, choose "About this Mac" and then click System Report.
This command, as written, also requires that you're running it as the logged in user, so if you're trying to get this info remotely it's also potentially going to fail.
So sorry for the back and forth. We are trying to do 0 touch deployment and need this information for inventory keeping. It worked for one person who doesn't have M1 chip. For the rest of our team with an M1 chip it doesn't work it pulls this up.
Screen Shot 2022-07-28 at 12.29.16 PM.png
 

chrfr

macrumors G5
Jul 11, 2009
13,703
7,267
So sorry for the back and forth. We are trying to do 0 touch deployment and need this information for inventory keeping. It worked for one person who doesn't have M1 chip. For the rest of our team with an M1 chip it doesn't work it pulls this up. View attachment 2035641
This isn't going to work in a zero touch deployment. Your MDM system should easily collect this data and report on it; I would use that rather than trying to come up with another way to do the same job.
Edit: also that preference file is only generated when System Report/System Information has been launched and quit in the GUI. Neither of these events can be relied on in a ZT deployment environment.
 
Last edited:

bogdanw

macrumors 603
Mar 10, 2009
6,099
3,013

chrfr

macrumors G5
Jul 11, 2009
13,703
7,267
Just to reiterate, this is one of the most basic functions available in an MDM system, which the OP has to be using if they're doing zero touch deployment. There's no need to come up with any other method.
In Jamf Pro, I can generate this report with just about any conceivable data needed about the client systems, and export it to a CSV file, in about 3 clicks.
 

Fishrrman

macrumors Penryn
Feb 20, 2009
29,183
13,229
How about:
 

BanditoB

macrumors 6502
Feb 24, 2009
482
258
Chicago, IL
@chrfr - I checked the com.apple.SystemProfiler.plist file for my system and it was dated back in 2020, so must have migrated over from my M1 MacBook Pro, so I dropped it into the Trash. I then ran System Information and no new plist was created. I clicked on Updates and it took me into System Preferences and checked for an update and after that I had a new com.apple.SystemProfiler.plist, but it was much smaller than the original.

I then re-executed the terminal command, "defaults read ~/Library/Preferences/com.apple.SystemProfiler.plist 'CPU Names' | cut -sd '"' -f 4 | uniq" but it tells me that CPU Names doesn't exist.

Next, I went back into System Information and under the File menu there was an option to refresh the list, which I did and this resulted in a plist file that was about twice as large as the previous version, but still about half the size of the original and the defaults read command still can't find CPU Names.

Do you have any idea on how to get my system to regenerate the full SystemProfiler.plist file? It's not a big deal, but I'm wondering if I'm doing something wrong.
 

chrfr

macrumors G5
Jul 11, 2009
13,703
7,267
@chrfr - I checked the com.apple.SystemProfiler.plist file for my system and it was dated back in 2020, so must have migrated over from my M1 MacBook Pro, so I dropped it into the Trash. I then ran System Information and no new plist was created. I clicked on Updates and it took me into System Preferences and checked for an update and after that I had a new com.apple.SystemProfiler.plist, but it was much smaller than the original.

I then re-executed the terminal command, "defaults read ~/Library/Preferences/com.apple.SystemProfiler.plist 'CPU Names' | cut -sd '"' -f 4 | uniq" but it tells me that CPU Names doesn't exist.

Next, I went back into System Information and under the File menu there was an option to refresh the list, which I did and this resulted in a plist file that was about twice as large as the previous version, but still about half the size of the original and the defaults read command still can't find CPU Names.

Do you have any idea on how to get my system to regenerate the full SystemProfiler.plist file? It's not a big deal, but I'm wondering if I'm doing something wrong.
On the computer I tried, the file was regenerated when opening System Information and then quitting it. Aside from the file not necessarily existing, I don't think it's a reliable data source for this information. The file can also be manually edited and that edit remains indefinitely.
 

BanditoB

macrumors 6502
Feb 24, 2009
482
258
Chicago, IL
Thanks @chrfr !

What I've found is that the com.apple.SystemProfiler.plist on seems to contain only window position information now. There is no other information in the file when I just perform a defaults read with no parameters. This makes sense to me as it's this type of info that plist files were really intended to contain.

I'm thinking that older versions of System Information wrote more data here, but the current one, V11.0, does not.
 

chrfr

macrumors G5
Jul 11, 2009
13,703
7,267
Thanks @chrfr !

What I've found is that the com.apple.SystemProfiler.plist on seems to contain only window position information now. There is no other information in the file when I just perform a defaults read with no parameters. This makes sense to me as it's this type of info that plist files were really intended to contain.

I'm thinking that older versions of System Information wrote more data here, but the current one, V11.0, does not.
The computer I used to test is an M1 Mini, running 12.5, so it's also on that same version of System Information, and it does write the CPU name in a new copy of the file if I delete it, but again, this is so unreliable and depends on the GUI to even have a chance of working, so it can't solve the OP's issue.
 
  • Like
Reactions: NoBoMac
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.