How characters in Computer Name field get mapped to local hostname field?

In System Preferences -> Sharing, we can see and change Computer Name, like "Bob's Macbook Pro", the system will convert it to Local Hostname like "Bobs-Macbook-Pro". Is there any documents describe how to convert the special characters in Computer Name to Local Hostname?


Thanks,

xhu

Replies

Found 2 documents that seem interesting:

h ttps://apple.lib.utah.edu/bonjour-naming-guidelines/

Explains which characters are allowed.


And this one provides some information on local name.

h ttps://uberagent.com/blog/choosing-macos-computer-names-wisely/


In particular, defines the different ways to name a computer.

the hostname, unlike the local hostname, is allowed to contain spaces and special characters. That makes the hostname as bad a choice as the computer name to store the machine name. Top that off with more or less unpredictable name changeswhenever the machine’s network connection changes, at least when relying on the automatic naming mechanisms, and hostname is definitely out of the game.


Apparently, special characters (are not allowed in local hostname. I would guess they are replaced by hyphen.

This process is way more complex than you might think. The difficulty is that the host name is derived from the computer name and the computer name can contain arbitrary characters, including characters from non-Latin scripts.

Try this: Set you computer name to

トトロ
[1]. When you do this, the local hostname changes to
totoro.local
. That’s is very cool. And it also applies across languages. A computer name of U+967d U+5149 [2] translates to a local hostname of
yangguang.local
, and so on.

The actual algorithm is not documented and, AFAIK, there’s no API access to it. However, the underlying primitives are available [3]. Specifically:

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

[1] The name of the main character from My Neighbor Totoro.

[2] One of the pandas at Edinburgh zoo. DevForums will not, alas, let me post the Han characters.

[3] While it uses CF APIs for this, most of these APIs have NS, and hence Swift-friendly, equivalents.

[4]

CFStringTransform
supports arbitrary ICU string transforms. The transform used currently is
Latin; Latin-ASCII; [^-._a-z0-9A-Z] Remove
, although that has changed in the past and it’s not hard to image it changing again in the future.
I was formerly able to name my computer using Greek letters, and Xcode ID'd it as such. Since Big Sur (I think) I cannot use Greek characters and have had to rename my computer. This may be the source of errors I get in Xcode
"[plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x600003023760> F8BB1C28-BAE8-11D6-9C31-00039315CD46
HALC_ShellDriverPlugIn::Open: opening the plug-in failed, Error: 2003329396 (what)" when trying to launch an .mov file from within my code. Searches provide varied but unsuccessful suggestions.
I have since renamed my device ID with Developer, but the above still occurs.

Eskimo's reply predates Big Sur and he was able to enter "foreign" characters.

Or is there something else I'm missing?

My Totoro example still works on mac OS 11 (just tested it on 11.1). I also tried entering Greek and it works as well (a computer name of Ελευθέριος Βενιζέλος maps to a local host name of Eleutherios-Benizelos.local [1])

I’m not in a position to test whether it triggers problems in the Xcode workflow but, if it does, that’s definitely bugworthy.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"

[1] This should probably be Eleftherios-Venizelos.local but there’s problem some Greek transliteration subtlety I don’t understand here.