0

I'm finally getting some headway made in my script for InDesign CS6. Now, in order for it to know to which printer it should print a document, I need to query which computer the script is running on. Barring that, perhaps the name of the currently logged-in user, which is really the same thing. This is a Mac OS X environment, by the way. Can anyone help or at least point me in the right direction?

Sturm
  • 689
  • 2
  • 23
  • 52

1 Answers1

3

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.

dln385
  • 11,630
  • 12
  • 48
  • 58
  • I see where you're going with this, @dln385, but I'm afraid both `$.getenv();` and `$.getenv("HOSTNAME");` return `null`. I'm going to see if there's a list of Mac OS X environment variables somewhere online. And we're not using the Server flavor, just regular ol' InDesign CS6. – Sturm May 17 '13 at 18:17
  • Playing with that `$.getenv()` method, I discovered `$.getenv("USER")` _does_ actually return the currently logged-in user, which should be good enough for my purposes. If, however, you happen to discover the environment variable that Mac OS X 10.8 uses for the computer name as well, @dln385, please let me know. Thanks! – Sturm May 17 '13 at 18:49
  • See that. That seems like an awful lot of code just to get the name of the computer on which the script is running. Anyway, I think we'll stick with the `$.getenv("USER")` method for now. Thanks for the help! – Sturm May 17 '13 at 20:11