Rename a mac with bash scripting

Gilbert J Palau
Enterprise macOS
Published in
1 min readApr 19, 2018

Here at the “Mothership” we had a big problem. Apple Mac computers were not named in a coherent way, that and some of our users didn’t like having an intangible name on their macs, so they would go and named the macs after their dogs and cats.

So I wrote a Mac Rename Script that checks what type of computer you have, if you have a laptop it ads the prefix ML- for Mac Laptop and if you have a Workstation (Mac Mini, iMac or Mac Pro) it ads MW- then after the model is chosen, it attaches the serial number of the mac to the name like this:

ML-C1MG00NSM0236T6

In order to make the users unable to change the name I attach it to the login hook, that way if I see a computer named differently I can reboot the Mac in question and it will be renamed accordingly.

rename script

Back in the Day, the best way to add this to your mac’s would be by login hook and logout hook like this:

But I highly recommend you do this with a Launch Agent rather than a login hook because that method is deprecated.

--

--

Gilbert J Palau
Enterprise macOS

macOS Wizard at computer on wheels car company, High Cleric of Nano, Curator of Fine Coffee, Destroyer of Tacos, Scourge of Crafted Beer.