• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Preventing extraneous output from osascript -l JavaScript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Pulling Data from AppleScript (From: Jon Rosen <email@hidden>)
 >Re: Preventing extraneous output from osascript -l JavaScript (From: Axel Luttgens <email@hidden>)
 >Re: Preventing extraneous output from osascript -l JavaScript (From: Paul Scott <email@hidden>)

  • Prev by Date: Re: AS Library Question
  • Next by Date: Re: Preventing extraneous output from osascript -l JavaScript
  • Previous by thread: Re: Preventing extraneous output from osascript -l JavaScript
  • Next by thread: Re: Preventing extraneous output from osascript -l JavaScript
  • Index(es):
    • Date
    • Thread