Skip to main content
Participating Frequently
April 10, 2025
Answered

Adding extra security in Javascipt for Indesign

  • April 10, 2025
  • 1 reply
  • 310 views

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);

Correct answer Manan Joshi

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

 

1 reply

Manan JoshiCommunity ExpertCorrect answer
Community Expert
April 10, 2025

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
ak_1809Author
Participating Frequently
April 10, 2025

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

Community Expert
April 10, 2025

Thanks for the update.

-Manan

-Manan