Skip to content

Script: GetEnvironmentVariable

SamuelPlentz edited this page Jul 4, 2022 · 2 revisions

Get environment variable from the operating system. It should return the value of any variable that is defined by the operating system. For example: USERNAME, COMPUTERNAME, HOMEPATH, TEMP, ...

Script

Scriptname: GetEnvironmentVariable

let type = this.mVariables[0];

try {
  var environment = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
  return environment.get(type);
} catch (e) {
  return("Error Ci.nsIEnvironment.get(" + type + "): " + e);
}

Usage

Get environment variable USERNAME:

[[SCRIPT=GetEnvironmentVariable|USERNAME]]

Get environment variable COMPUTERNAME:

[[SCRIPT=GetEnvironmentVariable|COMPUTERNAME]]

Get environment variable HOMEPATH:

[[SCRIPT=GetEnvironmentVariable|HOMEPATH]]

Get environment variable TEMP:

[[SCRIPT=GetEnvironmentVariable|TEMP]]

Script for variables, that depend upon the environment variables

Scriptname: GetDocumentpath

var computername = this.mQuicktext.process_script(['GetEnvironmentVariable', 'COMPUTERNAME']);

var documentpath = '';
if(computername == "computer1") documentpath = 'C:\Documents\';
if(computername == "computer2") documentpath = 'D:\Important\Documents\';

return documentpath;

Usage for variables, that depend upon the environment variables

[[SCRIPT=GetDocumentpath]]
Clone this wiki locally