JavaScript shell scripting

September 3rd, 2009. Tagged: JavaScript

As you probably know, JavaScript is not limited to the browser. There's server-side JavaScript, JS for various extensions, you can script Photoshop operations with JavaScript if you feel like it. Or compile Windows executables. You see where I'm going with this. JavaScript is everywhere :)

And yes, you can do shell scripting in JavaScript. On any platform you can use Rhino to run your scripts. On Windows there's this WSH, Windows Scripting Host you can benefit from, built right into the OS so you don't have to install anything. You can run your JavaScript shell scripts with the cscript utility like:

C:\> cscript jslint.js

And on the Mac there's JavaScriptCore by WebKit. WebKit is not limited to Safari, it's used all over the place on the Mac. So there's a utility called jsc which can run your scripts.

JSC test run

JSC (JavaScriptCore) is well hidden in

/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc

Check it out, it should be there. And if it is, why not use it via a "shortcut"? So step 1:

$ sudo ln /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc /bin/jsc

Step 2... no, there's no step 2, just give it a shot:

$ jsc -h
Usage: jsc [options] [files] [-- arguments]
  -d         Dumps bytecode (debug builds only)
  -e         Evaluate argument as script code
  -f         Specifies a source file (deprecated)
  -h|--help  Prints this help message
  -i         Enables interactive mode (default if no files are specified)
  -s         Installs signal handlers that exit on a crash (Unix platforms only)

So you can just run any JavaScript code on the command line. You can also use jsc as a JavaScript console to type away stuff. Probably not that useful, because you have Firebug console to type into. But still, an option.

$ jsc
> var a = 1;
undefined
> a++
1
> a
2
> 

Shell version of an online tool

Here's an example. Last night I worked on a quick hack to experiment with minifying CSS. There's an online tool over here as a result. Can I run this tool on the command line? Sure.

So imagine you have a JavaScript that parses CSS that looks like this. It defines an object called cssparse. You can use it in a browser-based tool, but also in the command-line version, without any changes. All you need is to create a new file that will be the shell version of the tool, say csspsh.js. In it put the something like:

if (!arguments[0]) {
    print('usage:\n $ jsc csspsh.js "`cat parseme.css`"');
    quit();
}
 
load('cssp.js');
 
print(cssparse.parse(arguments[0]));

You can probably guess but:

  • arguments[] array-like object contains command-line arguments
  • print() prints to the console
  • quit() exits JSC
  • load() loads and executes an external file

How do you pass arguments to your shell script? After a -- delimiter, like so:

$ jsc csspsh.js -- one two three

And since this particular script works with contents of files, I can use cat to read the file and pass it to the script.

$ jsc csspsh.js -- "`cat my.css`"

Shell-script away!

So there you have it. Shell scripting with JavaScript is at your fingertips, either Mac or Windows, or anywhere with Rhino. If you have some cool scripts that you want to run the on the command line, like cron jobs or some automated process, there has never been a better time :)

Tell your friends about this post: Facebook, Twitter, Google+

45 Responses

  1. Nice didn’t know about the shell possibilities of JS

  2. [...] JavaScript shell scripting / phpied.com http://www.phpied.com/javascript-shell-scripting – view page – cached Stoyan’s blog about (x)html, ajax, bookmarklets, browsers, css, firebug, javascript, json, mdb2, mysql, pear, performance, php, phpbb, tools, yslow, yui, writing, music,… life and everything. — From the page [...]

  3. [...] Enter Stoyan Stefanov who wrote a neat little blog post explaining how you can use JavaScript as a shell language. [...]

  4. Nice article. A few additions:

    Narwhal (http://narwhaljs.org) gives you a whole library of tools, including an options parser for creating command line scripts. I believe there’s work going on to create engines for all of the JavaScript interpreters you mentioned.

    On windows, you can make a .wsf file, just an XML file with “job” as the root and put as many script tags as you want to load multiple scripts at once:

    <job>
    <script language=”javascript” src=”prototype.js”><\/script>
    <script language=”javascript” src=”prototype.js”>
    var youGetTheIdea;
    <\/script>
    <\/job>

  5. This is great stuff!

    I’m trying to get it working in Windows… I can’t seem to find any way to “echo” messages to the console. print() doesn’t work… Additionally there doesn’t seem to be an “arguments” object or anything else you mentioned.

  6. Sorry if I am not waving with enthusiasm, but why use javascript when one could use ruby or python?

  7. [...] original here:  JavaScript shell scripting / phpied.com SHARETHIS.addEntry({ title: “JavaScript shell scripting / phpied.com”, url: [...]

  8. [...] Enter Stoyan Stefanov who wrote a neat little blog post explaining how you can use JavaScript as a shell language. [...]

  9. I really recommend narwhal http://www.narwhaljs.org . It is a young project but growing rapidly

    I use it for writing shell scripts that are cross platform. It has nice file, network, and direct shell access.

    Python is really better for shell scripting but it is easier these days to find people who know javascript than python, esp. when u are writing shell script for web developers to hack on, as i am

  10. @mark – try WScript.Echo(“Hello”)

  11. You might (or might not) be interested in Mahlee — on my web site — which is a multi-threaded JavaScript host for Windows. It includes a REPL shell as well for JScript which gives it some use as a shell.

  12. James: Please see the MS Windows Scripting Host documentation:

    http://msdn.microsoft.com/en-us/library/h8f603s7(VS.85).aspx

    If you use cscript.exe this will echo to the console/stdout. However if you use wscript.exe it will present a popup window.

    mark: Because that’s the language some people prefer

  13. [...] JavaScript shell scripting / phpied.com [...]

  14. [...] Enter Stoyan Stefanov who wrote a neat little blog post explaining how you can use JavaScript as a shell language. [...]

  15. [...] JavaScript shell scripting / phpied.comphpied.com [...]

  16. Similar to your first tool mentioned, check out Jash, a JS shell favelet.

    http://billyreisinger.com/jash/

    I find it to be friendlier in some ways than using the Firebug console when understanding what’s going on or trying new things.

  17. [...] just learned about jsc, a console Apple includes with the JavscriptCore library that I believe every version of OS X has [...]

  18. [...] Read the original:  JavaScript shell scripting / phpied.com [...]

  19. [...] Enter Stoyan Stefanov who wrote a neat little blog post explaining how you can use JavaScript as a shell language. [...]

  20. [...] JavaScript shell scripting Ja, das geht natürlich. Eigentlich gar keine schlechte Idee [...]

  21. Here is an option parser lib that works with all JS interpreters:
    http://github.com/jfd/optparse-js/tree/master

  22. [...] JavaScript shell scripting / phpied.com Interesting. Covers or mentions WSH, Rhino, and in particular JSC (JavaScriptCore) on the Mac. (tags: tutorial javascript shell scripting) [...]

  23. My HP computer has a “health check” script. It is written in js. Looks like that :
    /*
    * HPActiveCheck.js – entry point script for local mode execution of the Active Check.
    *
    * $Id: HPActiveCheck.js,v 1.55.32.1.8.1.54.1 2007/12/18 13:11:13 edias Exp $
    */

    // comment or disable to disable debugging msgs
    var ACLM_DEBUG = false;
    var currentArquitecture = “”;
    /* create a datamgr instance for our objects to use and load needed jscript files*/
    //var hpis = null;
    var activeCheckScript = null;

    try {
    //hpis = new ActiveXObject(“HPISDataManager.Datamgr”);
    var wsh = new ActiveXObject(“WScript.Shell”);

    var activeCheckRoot;

    try{
    currentArquitecture = wsh.RegRead(“HKLM\\Software\\Hewlett-Packard\\CPSS\\ActiveCheck\\Architecture”);
    }catch(e)
    {
    currentArquitecture = “”;
    }
    if (currentArquitecture==”"){
    try{
    currentArquitecture = wsh.RegRead(“HKLM\\Software\\Wow6432Node\\Hewlett-Packard\\CPSS\\ActiveCheck\\Architecture”);

    }catch(e)
    {
    currentArquitecture = “”;
    }
    }

    if (currentArquitecture == “32-bit”)
    {
    activeCheckRoot = wsh.RegRead(“HKLM\\Software\\Hewlett-Packard\\CPSS\\ActiveCheck\\Path”);
    }else
    {
    activeCheckRoot = wsh.RegRead(“HKLM\\Software\\Wow6432Node\\Hewlett-Packard\\CPSS\\ActiveCheck\\Path”);
    }

    var fso = new ActiveXObject(“Scripting.FileSystemObject”);

    var fileUtils = fso.OpenTextFile(activeCheckRoot + “\\utils.js”,1,true);
    var stringUtils = fileUtils.ReadAll();
    fileUtils.Close();
    eval(stringUtils);

    }
    catch(e) {
    var errMsg = e;

    try {
    errMsg += “: ” + e.description;
    }
    catch(e) {
    }
    utils.logError(“FATAL: Error loading required modules, please check your installation; (error: ” + errMsg + “)”);
    WScript.Quit(1);
    }

    function buildCommandLine(arguments,architecture)
    {
    var applicationName = “”;
    if (architecture==”32-bit”){
    applicationName = wsh.RegRead(“HKLM\\SOFTWARE\\Hewlett-Packard\\CPSS\\ActiveCheck\\ApplicationName”);
    }else{
    applicationName = wsh.RegRead(“HKLM\\SOFTWARE\\Wow6432Node\\Hewlett-Packard\\CPSS\\ActiveCheck\\ApplicationName”);
    }
    var stringArgs = “”;
    for(var i = 0; i < arguments.length; i++) {
    var argument = arguments(i).toLowerCase();

    switch (argument) {
    case “/detect”:
    case “/detect-unlocked”:
    case “/syncapp”:
    case “/syncaclm”:
    case “/syncasset”:
    case “/syncobj”:
    case “/fullcycle”:
    case “/no-session-lock”:
    case “/debug”:
    stringArgs += argument + ” “;
    break;
    case “/detectpm”:
    case “/fullcyclepm”:
    if (applicationName == “Smart Desktop”){
    stringArgs += argument + ” “;
    }else {
    throw “Unknown option: ” + argument;
    }
    break;
    default:
    throw “Unknown option: ” + argument;

    }

    }
    return stringArgs;
    }

    /** App entry point **/
    function main()
    {
    var shell = new ActiveXObject(“WScript.Shell”);

    var cmdLine = WScript.Arguments;
    var msg;
    var activeCheckRoot = “”;
    var WinSystemDir = “”;
    try {

    var argsLine = buildCommandLine(cmdLine,currentArquitecture)

    if (currentArquitecture == “32-bit”)
    {
    activeCheckRoot = wsh.RegRead(“HKLM\\Software\\Hewlett-Packard\\CPSS\\ActiveCheck\\Path”);
    WinSystemDir = shell.ExpandEnvironmentStrings(“%WinDir%”) + “\\System32\\”;
    }else
    {
    activeCheckRoot = wsh.RegRead(“HKLM\\Software\\Wow6432Node\\Hewlett-Packard\\CPSS\\ActiveCheck\\Path”);
    WinSystemDir = shell.ExpandEnvironmentStrings(“%WinDir%”) + “\\SysWow64\\”;
    }

    var retCode = wsh.run(WinSystemDir + “cscript \”" + activeCheckRoot + “HPActiveCheck.wsf\” “+ argsLine, 0, true);
    WScript.Quit(retCode);
    } catch(exception) {
    utils.logError(“HP Active Check finished with error:\n\t” + exception + msg);
    }
    }

    main();

    // SIG // Begin signature block
    // SIG // MIIVHwYJKoZIhvcNAQcCoIIVEDCCFQwCAQExDjAMBggq
    // SIG // hkiG9w0CBQUAMGYGCisGAQQBgjcCAQSgWDBWMDIGCisG
    // SIG // AQQBgjcCAR4wJAIBAQQQEODJBs441BGiowAQS9NQkAIB
    // SIG // AAIBAAIBAAIBAAIBADAgMAwGCCqGSIb3DQIFBQAEEOo9
    // SIG // I3THesgWEQJ1O1AMX7mgghEmMIIDejCCAmKgAwIBAgIQ
    // SIG // OCXX+vhhr570kOcmtdZa1TANBgkqhkiG9w0BAQUFADBT
    // SIG // MQswCQYDVQQGEwJVUzEXMBUGA1UEChMOVmVyaVNpZ24s
    // SIG // IEluYy4xKzApBgNVBAMTIlZlcmlTaWduIFRpbWUgU3Rh
    // SIG // bXBpbmcgU2VydmljZXMgQ0EwHhcNMDcwNjE1MDAwMDAw
    // SIG // WhcNMTIwNjE0MjM1OTU5WjBcMQswCQYDVQQGEwJVUzEX
    // SIG // MBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAMT
    // SIG // K1ZlcmlTaWduIFRpbWUgU3RhbXBpbmcgU2VydmljZXMg
    // SIG // U2lnbmVyIC0gRzIwgZ8wDQYJKoZIhvcNAQEBBQADgY0A
    // SIG // MIGJAoGBAMS18lIVvIiGYCkWSlsvS5Frh5HzNVRYNerR
    // SIG // Nl5iTVJRNHHCe2YdicjdKsRqCvY32Zh0kfaSrrC1dpbx
    // SIG // qUpjRUcuawuSTksrjO5YSovUB+QaLPiCqljZzULzLcB1
    // SIG // 3o2rx44dmmxMCJUe3tvvZ+FywknCnmA84eK+FqNjeGkU
    // SIG // e60tAgMBAAGjgcQwgcEwNAYIKwYBBQUHAQEEKDAmMCQG
    // SIG // CCsGAQUFBzABhhhodHRwOi8vb2NzcC52ZXJpc2lnbi5j
    // SIG // b20wDAYDVR0TAQH/BAIwADAzBgNVHR8ELDAqMCigJqAk
    // SIG // hiJodHRwOi8vY3JsLnZlcmlzaWduLmNvbS90c3MtY2Eu
    // SIG // Y3JsMBYGA1UdJQEB/wQMMAoGCCsGAQUFBwMIMA4GA1Ud
    // SIG // DwEB/wQEAwIGwDAeBgNVHREEFzAVpBMwETEPMA0GA1UE
    // SIG // AxMGVFNBMS0yMA0GCSqGSIb3DQEBBQUAA4IBAQBQxUvI
    // SIG // JIDf5A0kwt4asaECoaaCLQyDFYE3CoIOLLBaF2G12AX+
    // SIG // iNvxkZGzVhpApuuSvjg5sHU2dDqYT+Q3upmJypVCHbC5
    // SIG // x6CNV+D61WQEQjVOAdEzohfITaonx/LhhkwCOE2DeMb8
    // SIG // U+Dr4AaH3aSWnl4MmOKlvr+ChcNg4d+tKNjHpUtk2scb
    // SIG // W72sOQjVOCKhM4sviprrvAchP0RBCQe1ZRwkvEjTRIDr
    // SIG // oc/JArQUz1THFqOAXPl5Pl1yfYgXnixDospTzn099io6
    // SIG // uE+UAKVtCoNd+V5T9BizVw9ww/v1rZWgDhfexBaAYMkP
    // SIG // K26GBPHr9Hgn0QXF7jRbXrlJMvIzMIIDxDCCAy2gAwIB
    // SIG // AgIQR78Zld+NUkZD99ttSA0xpDANBgkqhkiG9w0BAQUF
    // SIG // ADCBizELMAkGA1UEBhMCWkExFTATBgNVBAgTDFdlc3Rl
    // SIG // cm4gQ2FwZTEUMBIGA1UEBxMLRHVyYmFudmlsbGUxDzAN
    // SIG // BgNVBAoTBlRoYXd0ZTEdMBsGA1UECxMUVGhhd3RlIENl
    // SIG // cnRpZmljYXRpb24xHzAdBgNVBAMTFlRoYXd0ZSBUaW1l
    // SIG // c3RhbXBpbmcgQ0EwHhcNMDMxMjA0MDAwMDAwWhcNMTMx
    // SIG // MjAzMjM1OTU5WjBTMQswCQYDVQQGEwJVUzEXMBUGA1UE
    // SIG // ChMOVmVyaVNpZ24sIEluYy4xKzApBgNVBAMTIlZlcmlT
    // SIG // aWduIFRpbWUgU3RhbXBpbmcgU2VydmljZXMgQ0EwggEi
    // SIG // MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCpyrKk
    // SIG // zM0grwp9iayHdfC0TvHfwQ+/Z2G9o2Qc2rv5yjOrhDCJ
    // SIG // WH6M22vdNp4Pv9HsePJ3pn5vPL+Trw26aPRslMq9Ui2r
    // SIG // SD31ttVdXxsCn/ovax6k96OaphrIAuF/TFLjDmDsQBx+
    // SIG // uQ3eP8e034e9X3pqMS4DmYETqEcgzjFzDVctzXg0M5US
    // SIG // mRK53mgvqubjwoqMKsOLIYdmvYNYV291vzyqJoddyhAV
    // SIG // PJ+E6lTBCm7E/sVK3bkHEZcifNs+J9EeeOyfMcnx5iIZ
    // SIG // 28SzR0OaGl+gHpDkXvXufPF9q2IBj/VNC97QIlaolc2u
    // SIG // iHau7roN8+RN2aD7aKCuFDuzh8G7AgMBAAGjgdswgdgw
    // SIG // NAYIKwYBBQUHAQEEKDAmMCQGCCsGAQUFBzABhhhodHRw
    // SIG // Oi8vb2NzcC52ZXJpc2lnbi5jb20wEgYDVR0TAQH/BAgw
    // SIG // BgEB/wIBADBBBgNVHR8EOjA4MDagNKAyhjBodHRwOi8v
    // SIG // Y3JsLnZlcmlzaWduLmNvbS9UaGF3dGVUaW1lc3RhbXBp
    // SIG // bmdDQS5jcmwwEwYDVR0lBAwwCgYIKwYBBQUHAwgwDgYD
    // SIG // VR0PAQH/BAQDAgEGMCQGA1UdEQQdMBukGTAXMRUwEwYD
    // SIG // VQQDEwxUU0EyMDQ4LTEtNTMwDQYJKoZIhvcNAQEFBQAD
    // SIG // gYEASmv56ljCRBwxiXmZK5a/gqwB1hxMzbCKWG7fCCmj
    // SIG // XsjKkxPnBFIN70cnLwA4sOTJk06a1CJiFfc/NyFPcDGA
    // SIG // 8Ys4h7Po6JcA/s9Vlk4k0qknTnqut2FB8yrO58nZXt27
    // SIG // K4U+tZ212eFX/760xX71zwye8Jf+K9M7UhsbOCf3P0ow
    // SIG // ggS/MIIEKKADAgECAhBBkaFaOXjfz0llZjgdTHXCMA0G
    // SIG // CSqGSIb3DQEBBQUAMF8xCzAJBgNVBAYTAlVTMRcwFQYD
    // SIG // VQQKEw5WZXJpU2lnbiwgSW5jLjE3MDUGA1UECxMuQ2xh
    // SIG // c3MgMyBQdWJsaWMgUHJpbWFyeSBDZXJ0aWZpY2F0aW9u
    // SIG // IEF1dGhvcml0eTAeFw0wNDA3MTYwMDAwMDBaFw0xNDA3
    // SIG // MTUyMzU5NTlaMIG0MQswCQYDVQQGEwJVUzEXMBUGA1UE
    // SIG // ChMOVmVyaVNpZ24sIEluYy4xHzAdBgNVBAsTFlZlcmlT
    // SIG // aWduIFRydXN0IE5ldHdvcmsxOzA5BgNVBAsTMlRlcm1z
    // SIG // IG9mIHVzZSBhdCBodHRwczovL3d3dy52ZXJpc2lnbi5j
    // SIG // b20vcnBhIChjKTA0MS4wLAYDVQQDEyVWZXJpU2lnbiBD
    // SIG // bGFzcyAzIENvZGUgU2lnbmluZyAyMDA0IENBMIIBIjAN
    // SIG // BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvrzuvH7v
    // SIG // g+vgN0/7AxA4vgjSjH2d+pJ/GQzCa+5CUoze0xxIEyXq
    // SIG // wWN6+VFl7tOqO/XwlJwr+/Jm1CTa9/Wfbhk5NrzQo3YI
    // SIG // HiInJGw4kSfihEmuG4qh/SWCLBAw6HGrKOh3SlHx7M34
    // SIG // 8FTUb8DjbQqP2dhkjWOyLU4n9oUO/m3jKZnihUd8LYZ/
    // SIG // 6FePrWfCMzKREyD8qSMUmm3ChEt2aATVcSxdIfqIDSb9
    // SIG // Hy2RK+cBVU3ybTUogt/Za1y21tmqgf1fzYO6Y53QIvyp
    // SIG // O0Jpso46tby0ng9exOosgoso/VMIlt21ASDR+aUY58Du
    // SIG // UXA34bYFSFJIbzjqw+hse0SEuwIDAQABo4IBoDCCAZww
    // SIG // EgYDVR0TAQH/BAgwBgEB/wIBADBEBgNVHSAEPTA7MDkG
    // SIG // C2CGSAGG+EUBBxcDMCowKAYIKwYBBQUHAgEWHGh0dHBz
    // SIG // Oi8vd3d3LnZlcmlzaWduLmNvbS9ycGEwMQYDVR0fBCow
    // SIG // KDAmoCSgIoYgaHR0cDovL2NybC52ZXJpc2lnbi5jb20v
    // SIG // cGNhMy5jcmwwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsG
    // SIG // AQUFBwMDMA4GA1UdDwEB/wQEAwIBBjARBglghkgBhvhC
    // SIG // AQEEBAMCAAEwKQYDVR0RBCIwIKQeMBwxGjAYBgNVBAMT
    // SIG // EUNsYXNzM0NBMjA0OC0xLTQzMB0GA1UdDgQWBBQI9VHo
    // SIG // +/49PWQ2fGjPW3io37nFNzCBgAYDVR0jBHkwd6FjpGEw
    // SIG // XzELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWdu
    // SIG // LCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAzIFB1YmxpYyBQ
    // SIG // cmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5ghBw
    // SIG // uuQdENkpNLY4ynsDzLq/MA0GCSqGSIb3DQEBBQUAA4GB
    // SIG // AK46F7hKe1X6ZFXsQKTtSUGQmZyJvK8uHcp4I/kcGQ9/
    // SIG // 62i8MtmION7cP9OJtD+xgpbxpFq67S4m0958AW4ACgCk
    // SIG // BpIRSAlA+RwYeWcjJOC71eFQrhv1Dt3gLoHNgKNsUk+R
    // SIG // dVWKuiLy0upBdYgvY1V9HlRalVnK2TSBwF9e9nq1MIIF
    // SIG // GTCCBAGgAwIBAgIQet4MVlsdcpthxt+RlYl+AzANBgkq
    // SIG // hkiG9w0BAQUFADCBtDELMAkGA1UEBhMCVVMxFzAVBgNV
    // SIG // BAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZWZXJp
    // SIG // U2lnbiBUcnVzdCBOZXR3b3JrMTswOQYDVQQLEzJUZXJt
    // SIG // cyBvZiB1c2UgYXQgaHR0cHM6Ly93d3cudmVyaXNpZ24u
    // SIG // Y29tL3JwYSAoYykwNDEuMCwGA1UEAxMlVmVyaVNpZ24g
    // SIG // Q2xhc3MgMyBDb2RlIFNpZ25pbmcgMjAwNCBDQTAeFw0w
    // SIG // NzAyMDUwMDAwMDBaFw0wODAyMDkyMzU5NTlaMIHcMQsw
    // SIG // CQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTES
    // SIG // MBAGA1UEBxMJUGFsbyBBbHRvMSAwHgYDVQQKFBdIZXds
    // SIG // ZXR0LVBhY2thcmQgQ29tcGFueTE+MDwGA1UECxM1RGln
    // SIG // aXRhbCBJRCBDbGFzcyAzIC0gTWljcm9zb2Z0IFNvZnR3
    // SIG // YXJlIFZhbGlkYXRpb24gdjIxIDAeBgNVBAsUF0hld2xl
    // SIG // dHQtUGFja2FyZCBDb21wYW55MSAwHgYDVQQDFBdIZXds
    // SIG // ZXR0LVBhY2thcmQgQ29tcGFueTCBnzANBgkqhkiG9w0B
    // SIG // AQEFAAOBjQAwgYkCgYEAyQTIJ5UrzyzUSFZUNskBQA5I
    // SIG // tWGyu4L57lPn4tyko3xFBPvUSCaQ/7lnzJiLCbdS2qx8
    // SIG // Y+ASj4221mRx9sobkOi0st7ijeMLY1BRp0+e9quQ2TSD
    // SIG // j3nT2u7GlgfIXDTMloPw0KZr+ONHFDjj+JBGPEe/ECqQ
    // SIG // 6hcmaDkFbQpWvA8CAwEAAaOCAX8wggF7MAkGA1UdEwQC
    // SIG // MAAwDgYDVR0PAQH/BAQDAgeAMEAGA1UdHwQ5MDcwNaAz
    // SIG // oDGGL2h0dHA6Ly9DU0MzLTIwMDQtY3JsLnZlcmlzaWdu
    // SIG // LmNvbS9DU0MzLTIwMDQuY3JsMEQGA1UdIAQ9MDswOQYL
    // SIG // YIZIAYb4RQEHFwMwKjAoBggrBgEFBQcCARYcaHR0cHM6
    // SIG // Ly93d3cudmVyaXNpZ24uY29tL3JwYTATBgNVHSUEDDAK
    // SIG // BggrBgEFBQcDAzB1BggrBgEFBQcBAQRpMGcwJAYIKwYB
    // SIG // BQUHMAGGGGh0dHA6Ly9vY3NwLnZlcmlzaWduLmNvbTA/
    // SIG // BggrBgEFBQcwAoYzaHR0cDovL0NTQzMtMjAwNC1haWEu
    // SIG // dmVyaXNpZ24uY29tL0NTQzMtMjAwNC1haWEuY2VyMB8G
    // SIG // A1UdIwQYMBaAFAj1Uej7/j09ZDZ8aM9beKjfucU3MBEG
    // SIG // CWCGSAGG+EIBAQQEAwIEEDAWBgorBgEEAYI3AgEbBAgw
    // SIG // BgEBAAEB/zANBgkqhkiG9w0BAQUFAAOCAQEAFtkn1vyk
    // SIG // UygPPrw2ySEiDCAOIAMpbwT4gDnXZ9+4OgO1QnHbB58F
    // SIG // qLBm+GdQbkkfBVMBeZtx9Dv1jM63829bMe94YTXwQErJ
    // SIG // W6Hom4op5MTNrKM1n+QL49/krbgv/mI7QFmMGSmlqImc
    // SIG // Cey1y0hPefuU7xUsLcbC5nIXGDpNIAtXMd3fc+S61B/I
    // SIG // eZ9jyDRnDb5CBC2C8XnVuwoHPKGT0ZODhpzPv0yuc9nP
    // SIG // FMSITmmNtwNf2DvcikENqBgyINkwisFGndu0CV72iKK9
    // SIG // mZWT6gh55dr9esQVMfE70fZ4qWn9+Sa5COUs4IMqSiRD
    // SIG // dixIE50JxMAh0FgrDVvExa2OBDGCA2MwggNfAgEBMIHJ
    // SIG // MIG0MQswCQYDVQQGEwJVUzEXMBUGA1UEChMOVmVyaVNp
    // SIG // Z24sIEluYy4xHzAdBgNVBAsTFlZlcmlTaWduIFRydXN0
    // SIG // IE5ldHdvcmsxOzA5BgNVBAsTMlRlcm1zIG9mIHVzZSBh
    // SIG // dCBodHRwczovL3d3dy52ZXJpc2lnbi5jb20vcnBhIChj
    // SIG // KTA0MS4wLAYDVQQDEyVWZXJpU2lnbiBDbGFzcyAzIENv
    // SIG // ZGUgU2lnbmluZyAyMDA0IENBAhB63gxWWx1ym2HG35GV
    // SIG // iX4DMAwGCCqGSIb3DQIFBQCgbDAQBgorBgEEAYI3AgEM
    // SIG // MQIwADAZBgkqhkiG9w0BCQMxDAYKKwYBBAGCNwIBBDAc
    // SIG // BgorBgEEAYI3AgELMQ4wDAYKKwYBBAGCNwIBFTAfBgkq
    // SIG // hkiG9w0BCQQxEgQQA/Mxbjro8OEDu8E7jy5Y1zANBgkq
    // SIG // hkiG9w0BAQEFAASBgF3VPLNoKq2Hv1Okp/m9T+LfKH8F
    // SIG // gDzRjEnUlnVzpKblP0iawvSqX7NPmZKMihJy+Q4ZByi/
    // SIG // UZUxUxf3gQ5ejko7MNtZ3pJxVZMduCXWmhWHJYtQE6OL
    // SIG // YN/jmGbOejPmded2sbtH5e49AGVAah6QlreaSpdRGPCG
    // SIG // sP3Ro2yai0xmoYIBfjCCAXoGCSqGSIb3DQEJBjGCAWsw
    // SIG // ggFnAgEBMGcwUzELMAkGA1UEBhMCVVMxFzAVBgNVBAoT
    // SIG // DlZlcmlTaWduLCBJbmMuMSswKQYDVQQDEyJWZXJpU2ln
    // SIG // biBUaW1lIFN0YW1waW5nIFNlcnZpY2VzIENBAhA4Jdf6
    // SIG // +GGvnvSQ5ya11lrVMAwGCCqGSIb3DQIFBQCgWTAYBgkq
    // SIG // hkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJ
    // SIG // BTEPFw0wNzEyMTgxMzA4MThaMB8GCSqGSIb3DQEJBDES
    // SIG // BBCOvWN6J7cZVs6MxAOCiyirMA0GCSqGSIb3DQEBAQUA
    // SIG // BIGAkawZscDXrjg6VvUXMCJZXHPo7iVMlHGAaMpG/YAA
    // SIG // BrywXHrH6uwNGs17yxAAt1Q9zMTJl/1vg4ca3ocoLLbj
    // SIG // /nMZFo3MmSA/WIerTNpN25jIPakPy8IyZFHar43ivux9
    // SIG // nFa8hmMdmNm7CQQtqxw7JeeD32gMKPpmqNd3wVJlR2w=
    // SIG // End signature block

  24. As one of the initial developers of Narwhal I have to echo Nathan and Bryan’s recommendation :)

    We really try to make it as easy as possible to get started. Give it a try: http://narwhaljs.org/quick-start.html

    You can also write (server-side) web apps using Jack on Narwhal: http://jackjs.org

  25. [...] Stoyan of PHPIED.com has found the joy using javascript for scripting in the OS… [...]

  26. [...] Shared JavaScript shell scripting / phpied.com. [...]

  27. very cool & good tip, thank you very much for sharing.

  28. [...] JavaScript shell scripting / phpied.com via Ajaxian — a little more useful info on using jsc (tagged: jsc javascript shell console terminal scripting tutorial todo Mac OSX ) [...]

  29. [...] post: JavaScript shell scripting / phpied.com By admin | category: scripting, scripts | tags: archive, major, microsoft-videos, [...]

  30. [...] mode with it.You can get an interactive console of JavaScriptCore on os x. Details here: http://www.phpied.com/javascript…Insert a dynamic date hereView All 0 CommentsCannot add comment at this [...]

  31. [...] Mac OS X, you can use the jsc utility to automate your system using JavaScript or install JavaScript OSA to use JavaScript [...]

  32. cookies…

    [...]JavaScript shell scripting / Stoyan’s phpied.com[...]…

  33. It would be more appropriate to create your simlink to jsc in /usr/local/bin rather than /bin.

  34. webmaster ploiesti…

    [...]JavaScript shell scripting / Stoyan’s phpied.com[...]…

  35. przglądarka firefox…

    [...]JavaScript shell scripting / Stoyan’s phpied.com[...]…

  36. A nitpick: you really ought to create that link in /usr/bin (or /usr/local/bin). The /bin directory is reserved for programs which run in single-user mode (e.g. during bootup before any filesystems are mounted), and it’s good practice not to put anything there that doesn’t absolutely need to be.

  37. I’m not using js, but have a new Mac and wondered where it was. I’ve never seen a more concise and to the point answer to a question I had about where js was stored. It’s a perfect start for use. Thank you.

  38. [...] JavaScript on the Command Line via the wat talk. [...]

  39. I always spent my half an hour to read this website’s posts every day along with a cup of coffee.

  40. [...] X on the command line. Doing some Google searches, looks like people have been talking about this for a long time. Even more! Here is how to compile javascript to .exe in Windows. Didn’t even thought that [...]

  41. I am going to watch out for brussels. Pandora charm bracelets http://www.dldajiakan.com/forum.php?mod=viewthread&tid=184025

  42. I concur! For Ferrari recognized headphones, they look great. I could very well never in doing my life accomplish that look.

  43. If your own photostream consists of photos that – regardless of whether good and / or not : triggered some sort of spirited comments¡ä place, we need to see them!

  44. [...] a lovely doc up at PHPied that goes over all of the nitty gritty. However, for a quick [...]

  45. I hacked together a bash script to give this a more normal interface.

    With this in `/usr/local/bin/jsc`, you can just do `jsc [args]`

    #!/bin/bash
    ARGUMENTS=”"
    i=0;
    for arg in “$@”; do
    if [ $i -ne 0 ]; then
    ARGUMENTS=”$ARGUMENTS$arg “;
    fi
    ((i++))
    done

    /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc “$1″ — $ARGUMENTS

Leave a Reply