Posted on 01-31-2022 12:33 PM
Hello,
I'm pretty sure one of you will know this. I stumbled upon a script left by the previous administrator in our Jamf instance. It's a script to name machines. The naming convention uses Building + Laptop or Workstation + Last 7 digits of serial. For example, a laptop in the San Francisco building should be named like this: SFOMLP-xxxxxxx. A workstation would be named SFOMWS-xxxxxxx. Everything works well except the part where it determines whether it's a laptop or a workstation. That part of the script looks like this:
Solved! Go to Solution.
Posted on 01-31-2022 12:51 PM
Hey @JDaher looks like they where looking for Bluetooth but it may be better to use SPHardwareDataType instead check out this post and see if this works for you by @rtrouton: https://community.jamf.com/t5/jamf-pro/determine-if-mac-is-portable-or-desktop-via-script/m-p/50608
Posted on 02-01-2022 10:52 AM
Hi JDaher - try using wildcards
Posted on 01-31-2022 12:51 PM
Hey @JDaher looks like they where looking for Bluetooth but it may be better to use SPHardwareDataType instead check out this post and see if this works for you by @rtrouton: https://community.jamf.com/t5/jamf-pro/determine-if-mac-is-portable-or-desktop-via-script/m-p/50608
01-31-2022 01:30 PM - edited 01-31-2022 03:32 PM
Hi Gabe,
Thank you for the suggestion. I'm a little bit further but it's still failing.
I ran the command in terminal, just to test:
/usr/sbin/system_profiler SPHardwareDataType | grep "Model Identifier" | grep "Book"
This is the result: Model Identifier: MacBookPro18,3
So then I edited the script to:
01-31-2022 12:53 PM - edited 01-31-2022 01:11 PM
@JDaher Try this:
model=$(ioreg -l | grep "product-name" | cut -d "=" -f 2 | sed -e s/[^[:alnum:]]//g | sed s/[0-9]//g)
Posted on 01-31-2022 01:44 PM
Another option would be to check the power management for whether or not an internal battery is present.
if pmset -g batt | grep -i internalbattery > /dev/null; then
base="MLP"
else
base="MWS"
fi
Posted on 04-07-2023 05:28 PM
I like this approach. Simplified our rename script.
01-31-2022 03:29 PM - edited 01-31-2022 03:38 PM
Thank you all for your suggestions. It seems like there's a few ways to determine whether laptop or workstation, and the script can be edited accordingly. I think the problem I'm having is on this part of the statement:
if [[ $comptype == 'Book' ]];then
Posted on 02-01-2022 02:24 AM
@JDaher may I ask how can you get the building assigned to a Mac from Jamf Pro server? is it using API?
Posted on 02-01-2022 11:52 AM
The building is assigned manually in Jamf Pro, after a device has been enrolled in Jamf.
Posted on 02-01-2022 12:31 PM
yeah but I meant how do you get the building of a Mac enrolled in Jamf via a script?
Posted on 02-01-2022 12:57 PM
Posted on 02-02-2022 12:40 AM
Worked like a charm ... many thanks
Posted on 02-01-2022 10:52 AM
Hi JDaher - try using wildcards
Posted on 02-01-2022 12:17 PM
Bingo! I had tried that earlier but I goofed on the syntax and wrote *.Book instead of *Book*. Seems so obvious now...
Thank you and everyone else who pitched in, all your suggestions helped me sort things out and I learned a few things along the way. I really appreciate you all.
Posted on 02-02-2022 09:14 AM
Ah, you were thinking of regular expression notation which is even better and would like this:
if [[ $comptype =~ "Book" ]];then
(You won't want to use .* because the non-alpha characters in the result throw it off).
Posted on 03-21-2023 07:44 AM
Does this work for the following models?
Mac14,9
Mac14,10
Thank you!
Posted on 03-21-2023 10:49 AM
Well, it turned out that it is not working for the latest MacBooks ...
Posted on 03-22-2023 12:01 PM
I don't know about those models. The last models I used the script on were 2021 machines.
Posted on 03-23-2023 01:45 AM
Their "Model Name" does no longer contain "Book". Jamf knows them under e.g. model "Mac14,9" ...
Is there any other way to determine if it is a laptop or desktop device, ethernet port?