Hey guys,
I’m trying to rename a few macOS devices using user details, but on some devices the rename just doesn’t go through. No proper error, it just doesn’t stick. Not sure what I’m missing here—any ideas?
Hey guys,
I’m trying to rename a few macOS devices using user details, but on some devices the rename just doesn’t go through. No proper error, it just doesn’t stick. Not sure what I’m missing here—any ideas?
Hmm, I think I’ve heard of something like this before. What’s the username on one of the affected devices?
One of them is “Robert Williams”.
Ahh okay, yeah… that’s exactly what I was guessing 😄. The issue is the space. macOS (especially the LocalHostName part) doesn’t really handle spaces well. So, when the rename tries to apply that value directly, it just fails silently in some cases.
I had a small script saved for this kind of scenario—basically you pass the values and set the name explicitly instead of relying on the default rename behaviour:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#!/bin/bash # Check if exactly two arguments are provided if [ "$#" -ne 2 ]; then echo "Usage: $0 <arg1> <arg2>" exit 1 Fi # Combine the two arguments with a space NEW_NAME="$1$2" echo "Changing device name to: $NEW_NAME" # Set ComputerName (The user-friendly name seen in Finder) sudo scutil --set ComputerName "$NEW_NAME" # Set HostName (The name used for DNS and the command line) sudo scutil --set HostName "$NEW_NAME" # Set LocalHostName (The name used for AirDrop/Local Network) sudo scutil --set LocalHostName "$NEW_NAME" # Flush DNS cache to apply changes dscacheutil -flushcache echo "Success! Device name updated to '$NEW_NAME'." echo "Note: You may need to restart your terminal to see the changes in your prompt." |
You can pass stuff like %name% and %devicenotes% into it.
Ohhh got it, that makes sense now. But how would I run this on the device? It’s with a field employee, so I don’t have direct access.
Yeah that’s pretty common.
You don’t need physical access for this. Just use the execute script action from your console. Upload the script there, pass the required values as arguments, and push it to the device.
We’ve done this for remote users as well, works without any issues 👍
Don't have an account? Sign up