Re: Preventing extraneous output from osascript -l JavaScript
Re: Preventing extraneous output from osascript -l JavaScript
- Subject: Re: Preventing extraneous output from osascript -l JavaScript
- From: Axel Luttgens <email@hidden>
- Date: Thu, 17 Dec 2015 09:59:12 +0100
> Le 16 déc. 2015 à 23:44, Paul Scott a écrit :
>
>> On Dec 16, 2015, at 2:12 PM, Axel Luttgens wrote:
>>
>> […]
>> Anyway, it seems that the "problem" may be reduced to:
>>
>> #!/usr/bin/osascript -l JavaScript
>> var app = Application.currentApplication();
>> app.includeStandardAdditions = true;
>
> Let’s reduce it further:
>
> #!/usr/bin/osascript -l JavaScript
>
> Run that, and an extra linefeed is ejected. Of course, I can redirect stdout/stderr, but that’s not what I want to do. I want stdout/stderr directed to the terminal, and I want to see any output produced, *except* extraneous output from osascript such as the result of the last executed line or even a lowly linefeed.
>
> The Above single line script (assumed name q) should run like this:
>
> $ ./q
> $
>
> Not like this:
>
> $ ./q
>
> $
>
> I can achieve this result with -l AppleScript but not -l JavaScript specified. If there is nothing I can do within the script to avoid this inconsistent behavior, I will file a bug report.
But is this really a bug? Isn’t the execution of JavaScript code supposed to always return some value (even an "undefined" one, translated as an empty line by osascript)? If yes, it could be said that osascript’s behavior is the right one.
> But I thought I’d first ask if anyone had solution.
Well, the uncaught exception suggestion avoids extraneous output written to stdout:
#!/usr/bin/osascript -l JavaScript
// some useful code
// until one wants to leave without interfering with stdout:
throw 'Intended exit.';
But this has the side-effect to write an error message to stderr.
There could be another way, probably more costly:
#!/usr/bin/osascript -l JavaScript
ObjC.import("stdlib");
// some useful code
// until one wants to leave without interfering with stdout and stderr:
$.exit(0);
HTH,
Axel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden