brandonhorst/node-osa

multiline OSA script lines

Closed this issue · 8 comments

First of all: Thanks for providing this very helpful library!

Proposal for an enhancement:
For debugging the OSA function it would be helpful to run it in multiple lines. If an error is thrown, the message currently reference 'line 1' as the location. To accomplish this, I used the multiple -e option of osascript by replacing

var escapedCall = functionCallString.replace(/^\s+/g, ' ').replace(/\n/g, '').replace(/'/g, "'\\''");
var executeString = "osascript -l JavaScript -e '" + escapedCall + "'";

with

var escapedCall = functionCallString.replace(/^\s+/g, ' ').replace(/'/g, "'\\''").split('\n');
var executeString = "osascript -l JavaScript";
for (var i=1, r=0; r<escapedCall.length; r++) {
    console.log('*** ' + (i++) + ': ' + escapedCall[r]);
    executeString += " -e '" + escapedCall[r] + "'";
}

If this is too verbose, remove the 'console.log' line. Errors will now be reported in the respective line of the function with an offset of 1 for the prefix code itself - hence i starts counting at 1 in the for loop above.

Cheers,
-HS

That seems reasonable to me. Could you submit a PR?

This appears to be what I am working on now. Was any progress made here?

I'm open to PR's. It would be a quick fix, and I could get around to it eventually but not immediately

Same here. Although I'm actually new to node as well. Did OP push any of his changes?

Don't think he made any.

Ok, I’ll give it a go some time

On 18/06/2016, at 3:00 PM, Brandon Horst notifications@github.com wrote:

Don't think he made any.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub #4 (comment), or mute the thread https://github.com/notifications/unsubscribe/AQrCbb-HteFVDk_V_SmZTSeFvcAm0N60ks5qM19lgaJpZM4FliX8.

It looks like you already have a pull request for it.

#5

Oh jeez, right you are. Sorry for that absurd discussion! Merged, tested, and published.