Need JavaScript help

Yeah, me too, we’re both from the old days with the wounds to show it.

Still, every once in a while… Usually when you have something you really want to keep…

Thanks.

1 Like

Any idea how to out some debugging text? I used console.log(), and opened Atom’s developer tools, but I can’t find any place where the log message went. I would have thought the tab named “Console” would contain the output, but it doesn’t look like it.

Is there a shorter syntax for this, than separating the “var” and the assignment?

var _windows;
try {
    _windows = _xcodeProc.windows();
} catch (e) {
    throw "Xcode is probably not running.";
}

I think the Script package sends return values and console.log strings alike to the same output stream

( on ⌘I )

I personally avoid Try Catch, (prefer conditional values which don’t interrupt flow or prevent composition of nested functions) so I might write things like:

(function () {
    'use strict';

    var se = Application('System Events'),
        procs = se.applicationProcesses
        .where({
            name: "Xcode"
        }),
        blnRunning = procs.length > 0,
        
        proc = blnRunning ? procs[0] : undefined;
        
    if (proc) {
        var ws = proc.windows,
            w = ws.length ? ws[0] : undefined;
            
        return w && w.name();
    }

})();

Thanks for showing me how to check to see if the app is running. Didn’t think of that.

In general, unless I just don’t care, I want to know that something failed. So, if unchecked results will cause an error message that is understandable, at least by me, then I’d prefer to let it fail rather than check the result. In the case where the error won’t tell me what I’d need to know, then I want to throw an exception.

You’re used to this stuff. For you, you can debug things just fine, because you’ve probably seen it before. Not so, for me.

Thanks for the info.

1 Like