Last active
August 29, 2015 14:26
-
-
Save imlucas/00f48700c5ebe2aee54c to your computer and use it in GitHub Desktop.
How to get "Computer Name"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using the node -> objective-c bridge | |
var $ = require('nodobjc'); | |
var pool = $.NSAutoreleasePool('alloc')('init'); | |
$.framework('Foundation'); | |
var host = $.NSHost('currentHost'); | |
var name = host('name'); | |
console.log('NSHost.currentHost.name: `%s`', name); | |
// -> NSHost.currentHost.name: `lucas-macbook-pro.local` | |
$.framework('SystemConfiguration'); | |
var name = $.NSString('stringWithString', $.SCDynamicStoreCopyComputerName(null, null)); | |
console.log('SCDynamicStoreCopyComputerName: `%s`', name); | |
// -> SCDynamicStoreCopyComputerName `Lucas' MacBook Pro` | |
pool('drain'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using the completely unknown wscript | |
// https://msdn.microsoft.com/en-us/library/wck0hkd7(v=vs.84).aspx | |
var WshNetwork = WScript.CreateObject("WScript.Network"); | |
WScript.Echo("Computer Name = " + WshNetwork.ComputerName); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment