Set name from iMac M1 based on color

Jordy-Thery
New Contributor III

A customer of ours had an interesting question; they want to rename their Macs based on the color of the iMac. e.g "iMac Blue SerialNumber".

I can't seem to find any place where the color is referenced. In network sharing and in the about this Mac screen it shows the correct color so I assume it does store it somewhere. I found the icons but I can't pinpoint how it detects what color it is.

Any tips? Macs are running Ventura by the way

1 ACCEPTED SOLUTION

AJPinto
Honored Contributor II

Each model ID would need to be accounted for in the script. 

Just add more and update the existing if statements to turn MK193LL/A in to the color verb you are wanting. 

You need to add something like this, and you would need an if statement for each model number you want to cover. I would also put an if statement for if the Model Number does not equal one of your options so the script does not error. Id also add a function to skip all this mess if its not an iMac.

 

#!/usr/bin/env bash
serialNumber=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
modelNumber=$(system_profiler SPSoftwareDataType SPHardwareDataType | awk '/Model Number/ {print $3}')

if [ "Z12U000SEFN/A" == "$modelNumber" ]
then
	echo "Someone got a ping iMac"
	scutil --set ComputerName "pink $serialNumber"
else
	echo "thank god its not pink"
fi

if [ "MK193LL/A" == "$modelNumber" ]
then
	echo "Good, someone has the only correct color; space gray"
	scutil --set ComputerName "Space Gray $serialNumber"
else
	echo "Its not space gray?!?! What is wrong with this person"
fi

 

 

This will probably turn in to a reasonable long script, but thankfully it should not be a complicated one and it will repeat a lot. So once you have the verbiage down its just copy past and make adjustments. 

View solution in original post

10 REPLIES 10

AJPinto
Honored Contributor II

The model number will tell you the color. You could use a script to read the model number from system profiler and use some Variables to add the color to the host name.

 

For example:

  • MJV93LL/A is the blueish iMac
  • MJV83LL/A is the greenish iMac
  • MJVA3LL/A is the pinkish iMac

The Model number will change ever so slightly for different configurations like RAM, CPU, SSD and Color. The command below will pull the Model Number, the results need to be prettied up for a script but its entirely possible. JAMF is also aware of the Model Number, if you wanted to have different policies scoped to different model numbers and do it that way.

system_profiler SPSoftwareDataType SPHardwareDataType | grep "Model Number"

 

Jordy-Thery
New Contributor III

Hi AJPinto, thank you for your reply.

I tried that but on the machines it responds with a wrong model number I'm afraid (e.g: Model Number: Z12U000SEFN/A)

I also looked into https://georgegarside.com/blog/macos/imac-m1-accent-colours-any-mac/ but reading out that doesn't do much. 

I tried reading the defaults of global domain and look for the AppleAccentColor value as this is set to 'this Mac' but it returns a value of -1 so that's not really helpful. 

AJPinto
Honored Contributor II

It reports back fine on my device with system profiler. 

AJPinto_0-1680877932066.png

I just updated a script I use to name devices add a function for the model number. I have not tested it but it should set the hostname to Model Number Serial Number (example: MK193LL/A Q74V1234WX). Just add more and update the existing if statements to turn MK193LL/A in to the color verb you are wanting. MK193LL/A is for a Space Gray MBP16, it should report out correctly for whatever the device the script is run on has.

 

#!/usr/bin/env bash
#*=============================================================================
#* Script Name: 
#* Created: 
#* Author: 
#*=============================================================================
#* Purpose: Requests input and renames computer based on Naming Conventions
#*=============================================================================



#*=============================================================================
#* GLOBAL VARIABLES
#*=============================================================================
computerName=$(scutil --get ComputerName)
hostName=$(scutil --get HostName)
localHost=$(scutil --get LocalHostName)
serialNumber=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
serialNumberII=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}' | tr -d '"')
modelNumber=$(system_profiler SPSoftwareDataType SPHardwareDataType | awk '/Model Number/ {print $3}')

#*=============================================================================
#* SCRIPT BODY
#*=============================================================================

## Check & Update Computer Name
if [ "$computerName" == "$modelNumber $serialNumber" ]
then
	echo "Computer name matches serial number, $modelNumber $serialNumber"
else
	echo "Current Computer Name: $computerName"
	echo "Computer Name does not meet standards"
	echo "Changing Computer Name to match Serial Number"
	scutil --set ComputerName "$modelNumber $serialNumber"	
fi; $DIV2

## Check & Update Host Name
if [ "$hostName" == "$modelNumber $serialNumber" ]
then
	echo "Host Name matches serial number, $modelNumber $serialNumber"
else
	echo "Current Host Name: $hostName"
	echo "Host Name does not meet standards"
	echo "Changing Host Name to match Serial Number"
	scutil --set HostName "$modelNumber $serialNumber"
	
fi; $DIV2


## Check & Update Local Host
if [ "$localHost" == "$modelNumber $serialNumber" ]
then
	echo "Local Host matches serial number, $modelNumber $serialNumber"
else
	echo "Current Local Host: $localHost"
	echo "Local Host does not meet standards"
	echo "Changing Local Host to match Serial Number"
	scutil --set LocalHostName "$modelNumber $serialNumber"
	
fi; $DIV2


## Final Check
computerNameII=$(scutil --get ComputerName)
hostNameII=$(scutil --get HostName)
localHostII=$(scutil --get LocalHostName)

echo ""
echo "Serial number: $modelNumber $serialNumber"
echo "Computer Name: $computerNameII"
echo "Host Name: $hostNameII"
echo "Local Host: $localHostII"
if [[ "$computerNameII" == "$modelNumber $serialNumber" ]] && [[ "$hostNameII" == "$modelNumber $serialNumber" ]] && [[ "$localHostII" == "$modelNumber $serialNumber" ]] 
then 
	echo "Computer Name satisfies naming standards"
	$DIV1; exit 0
else
	echo "Computer does not meet naming standards"
	echo "More troubleshooting will be necessary."
    $DIV1; exit 1
fi 

## Perform final Recon to update computer name on Jamf
sudo jamf recon
#*=============================================================================
#* END OF SCRIPT
#*=============================================================================

 

 

I am not sure if I would try to read the color theme, that just seems like it would be a mess with how Apple does things. Id stick to system profiler, and convert the model number to a color with a if statement. 

Jordy-Thery
New Contributor III

Thank you for your response. I was thinking about converting the model number to the color via an if statement but am clueless why the system profiler reports back the wrong model number. 

system_profiler SPSoftwareDataType SPHardwareDataType | awk '/Model Number/

 Just comes back with "Z12U000SEFN/A" Mac is fully up-to-date.

*edit*

I guess its because the Mac is a built-to-order with different than basic specs. 😅

AJPinto
Honored Contributor II

What does Hardware information say? Z12U000SEFN/A is not a valid Model Number as far as I am aware. If you are testing on a VM this is one of the things that does not come through correctly. 

AJPinto_0-1680881409864.png

 

Jordy-Thery
New Contributor III

The hardware overview says the same. Z12U000SEFN/A is a valid model number though, it's a built-to-order Mac with following specs: Apple BTO IMAC 24" M1‑chip 8C CPU/8C GPU 16GB, 256GB GIGABIT MM MAGIC KBD TOUCH ID NUM AZERTY - GREEN

AJPinto
Honored Contributor II

Each model ID would need to be accounted for in the script. 

Just add more and update the existing if statements to turn MK193LL/A in to the color verb you are wanting. 

You need to add something like this, and you would need an if statement for each model number you want to cover. I would also put an if statement for if the Model Number does not equal one of your options so the script does not error. Id also add a function to skip all this mess if its not an iMac.

 

#!/usr/bin/env bash
serialNumber=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
modelNumber=$(system_profiler SPSoftwareDataType SPHardwareDataType | awk '/Model Number/ {print $3}')

if [ "Z12U000SEFN/A" == "$modelNumber" ]
then
	echo "Someone got a ping iMac"
	scutil --set ComputerName "pink $serialNumber"
else
	echo "thank god its not pink"
fi

if [ "MK193LL/A" == "$modelNumber" ]
then
	echo "Good, someone has the only correct color; space gray"
	scutil --set ComputerName "Space Gray $serialNumber"
else
	echo "Its not space gray?!?! What is wrong with this person"
fi

 

 

This will probably turn in to a reasonable long script, but thankfully it should not be a complicated one and it will repeat a lot. So once you have the verbiage down its just copy past and make adjustments. 

Jordy-Thery
New Contributor III

Hi,

You're right. :-) I've created an extension attribute to check the model number so I'll have a list of all the model numbers currently in use.

Thanks for the tips. Much appreciated!

AJPinto
Honored Contributor II

You are very welcome. If you would not mind I'd love to see the finished script if you could share it when you are done. I am sure it will be a beast lol.

Jordy-Thery
New Contributor III

Didn’t really find an easy way to check the default wallpaper. Since the Macs are all built-to-order iMacs and the model numbers are very random I had to resort to user input to rename the Macs instead.

I used this script together with Swift Dialog:

#!/bin/bash
dialogApp="/usr/local/bin/dialog"
title=“Rename this Mac”
message=“Please enter the location and Mac color.”
hwType=$(/usr/sbin/system_profiler SPHardwareDataType | grep “Model Identifier” | grep “Book”)
if [ “$hwType” != “” ]; then
icon=“SF=laptopcomputer”
else
icon=“SF=desktopcomputer”
fi
dialogCMD="$dialogApp -p --title “$title”
–icon “$icon”
–message “$message”
–small
–textfield “Location (e.g: Kortrijk)”
–textfield “Color (e.g: Blauw)”"
computerName=$(eval “$dialogCMD” | awk -F " : " ‘{print $NF}’)