Skip to main content
Participating Frequently
Apr 10, 2025 3:29 AM UTC
Answered

Adding extra security in Javascipt for Indesign

I wrote the below code to get username + hostname within Indesign. Works on windows but doesnt work on mac. It justs brings back username@null.

I assume its not possible to get hostname through Indesign. But can someone offer a solution or direct me to the right place. My goal is to limit the scripts I wrote to a specific computer with a unique identifier. If I can only do it with username than I guess that would have to do.


Any suggestion would be very helpful. Thank you

var userName = $.getenv("USERNAME") || $.getenv("USER"); // For Windows/macOS
var computerName = $.getenv("COMPUTERNAME") || $.getenv("HOSTNAME");
var uid = userName + "@" + computerName;

alert("Detected UID:\n" + uid);

Manan JoshiCorrect answer
Community Expert
Apr 10, 2025 3:45 AM UTC

HOSTNAME env variable might not be defined on the MAC you are executing. You can see the list of environment variables defined using the command "env"

From what I could search HOSTNAME may be undefined on shells other than bash so other way to retrieve it usign a command

hostname

What I think would be best is to execute an Applescript or shell script to get hostname. I can't recall if we are able to get back the return value from execution of a script file though. You can search the forum for this and experiment

-Manan

 

-Manan

3 replies

Manan JoshiCommunity ExpertCorrect answer
Community Expert
Apr 10, 2025 3:45 AM UTC

HOSTNAME env variable might not be defined on the MAC you are executing. You can see the list of environment variables defined using the command "env"

From what I could search HOSTNAME may be undefined on shells other than bash so other way to retrieve it usign a command

hostname

What I think would be best is to execute an Applescript or shell script to get hostname. I can't recall if we are able to get back the return value from execution of a script file though. You can search the forum for this and experiment

-Manan

 

Translate
-Manan
ak_1809Author
Participating Frequently
Apr 10, 2025 5:05 AM UTC

Thank you very muich for the suggestion. I took the apple script route and it was a success.

Translate
Community Expert
Apr 10, 2025 5:33 AM UTC

Thanks for the update.

-Manan

Translate
-Manan