How can I get the computer's name on a Mac? I'm talking about the same name as the one you can find in System Profiler under "Software".
Your computer's name is displayed at the top of the Sharing preferences pane. On your Mac, choose Apple menu > System Preferences, then click Sharing . If the lock at the bottom left is locked , click it to unlock the preference pane. Type a new name in the Computer Name field.
Objective C
The name I was looking for is:
[[NSHost currentHost] localizedName];
It returns "Jonathan's MacBook" rather than "Jonathans-Macbook", or "jonathans-macbook.local" which just name
returns.
Swift 3
For Swift >= 3 use.
if let deviceName = Host.current().localizedName { print(deviceName) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With