Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 6, 2012, 09:18 PM   #1
ArtOfWarfare
macrumors 68040
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Get Computer Name on Network?

Here's what I have right now...

using [[NSProcessInfo processInfo] hostName], I get names like:

"macintosh-85.resnet.neu.edu"

If the computer broadcasts a NSNetService, then receives its own service, and then resolves the address, it finds the name as being:

"macintosh-85.local." instead

First question: How can I get my program to recognize that the broadcast it's receiving is the same one it sent out?

Second question: Although these names are fine for behind the scenes purposes, I would like to get a name along the lines of

"Xxx Xxx's iMac"

to display to the user.

These friendly looking names (which appear in the sidebar of Finder under SHARED and DEVICES) appear to be set in System Preferences -> Sharing -> Computer Name. Does anyone know how I can access these names from my app? (A solution that works within the sandbox would be preferred, although if anyone knows how to make it work outside the sandbox, I'll happily take that solution and see what I can do with it...)

At the same time, the not so friendly looking name appears to come from just under the setting... the second name seems to be called the the "Local Hostname". I can't figure out what the first name (the one returned by ProcessInfo) is called.
__________________
Battery Status - On the Mac App Store
The only app that'll estimate when your wireless devices will need their batteries changed.
Like it on Facebook!
ArtOfWarfare is online now   0 Reply With Quote
Old Jun 6, 2012, 09:28 PM   #2
bogatyr
macrumors 65816
 
Join Date: Mar 2012
Some options:
http://stackoverflow.com/questions/4...er-name-on-mac

The first answer shows a way to get a "Xxx Xxx's iMac" result as requested:
[[NSHost currentHost] localizedName];
bogatyr is offline   0 Reply With Quote
Old Jun 6, 2012, 10:08 PM   #3
ArtOfWarfare
Thread Starter
macrumors 68040
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
There were comments there about NSHost blocking the main thread if the network is slow... will

Code:
NSString *computerName = [(NSString *)SCDynamicStoreCopyComputerName(NULL, NULL) autorelease];
Also block the main thread? Because it seems to give me what I want for a friendly looking name.
__________________
Battery Status - On the Mac App Store
The only app that'll estimate when your wireless devices will need their batteries changed.
Like it on Facebook!
ArtOfWarfare is online now   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 06:06 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC