Skip to content

Instantly share code, notes, and snippets.

@JiDai
Last active October 2, 2018 21:02
Show Gist options
  • Save JiDai/75177e2a04658ce0c0b2a437d75f5337 to your computer and use it in GitHub Desktop.
Save JiDai/75177e2a04658ce0c0b2a437d75f5337 to your computer and use it in GitHub Desktop.
Trace all env variable in JXA script
ObjC.import('stdlib');
var env = $.NSProcessInfo.processInfo.environment // -[[NSProcessInfo processInfo] environment]
env = ObjC.unwrap(env)
for (var k in env) {
console.log('"' + k + '": ' + ObjC.unwrap(env[k]))
}
// Helper to get one env variable
// Catch exception if the env variable not exists
const getenv = (varName) => {
// Handle exception: Error: exception raised by object: *** +[NSString stringWithUTF8String:]: NULL cString (-2700)
try {
return $.getenv(varName)
} catch (e) {
return null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment