As seen on http://jongware.mit.edu/idcs6js/pc_$.html, the $.getenv()
method can be used to get any environment variable. On Windows you could use $.getenv("COMPUTERNAME")
, and on Mac $.getenv("HOSTNAME")
should work.
Let me know if this doesn't work. I don't have a Mac to test on, but there's probably other options.
EDIT 1: Are you using InDesign Server? If so, app.serverHostName
and app.serverSettings.hostName
would work.
EDIT 2: Here's another possible solution:
var outputFile = new File(Folder.desktop.fsName + "/GetHostName.sh");
outputFile.open("w");
try {
outputFile.write("scutil --get HostName > ~/Desktop/HostName.txt");
}
finally {
outputFile.close();
}
outputFile.execute();
var inputFile = new File(Folder.desktop.fsName + "/HostName.txt");
inputFile.open("r");
try {
var hostName = inputFile.read();
}
finally {
inputFile.close();
}
$.writeln("Host Name: " + hostName);
The idea is to write a shell script to file and then execute it. The shell script gets the host name and writes it to a file. Then we open the file and read the host name.