Last active
October 2, 2018 21:02
-
-
Save JiDai/75177e2a04658ce0c0b2a437d75f5337 to your computer and use it in GitHub Desktop.
Trace all env variable in JXA script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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