Re: [ASOC] returning by reference, and converting script objects to descriptors?
Re: [ASOC] returning by reference, and converting script objects to descriptors?
- Subject: Re: [ASOC] returning by reference, and converting script objects to descriptors?
- From: has <email@hidden>
- Date: Sat, 16 Jan 2016 12:39:50 +0000
Shane Stanley wrote:
>
> On 16 Jan 2016, at 20:30, has <email@hidden> wrote:
>>
>> Does ASOC support return-by-argument, e.g. for getting NSError**?
>
> set {theResult, theError} to (theFileManager's
copyItemAtURL:theSourceURL toURL:theDestURL |error|:(reference))
Thanks. Kinda wonky design though; wonder why ASOC doesn't just take an
actual reference? What if it's an inout parameter - how do you pass a
value in?
>> Also, am I right that ASOC doesn't support block-based APIs at all,
e.g. NSTask.terminationHandler?
>
> No, there's no support for blocks. In this case you have to do
something yucky like:
>
> repeat while theTask's |isRunning|() as boolean
> delay 1.0E-5
> end repeat
Suspected as much. Would be nice if one could pass a script containing
just a standard `run` handler and have that invoked. Have you filed a
ticket on it?
As for this particular use case, -[NSTask isRunning] is deprecated, so
that's not an option.
> Running NSTask in ASObjC is about on-par with do shell script time-wise.
Yeah, I'm not bothered about that: everything in AppleScript [except AE
dispatch] is dog-slow compared to other languages (e.g. Python's sort
routine is 100x faster than mine, and stable to boot, so merely being
"as fast as" is actually a pretty good deal). The purpose of creating
these libraries is to provide greater capability, robustness, and ease
of use. The benefits of NSTask over `do shell script` are that it allows
you to interact with a Unix-style process directly, piping data in and
out, and to operate asynchronously as well as synchronously. (TBH, the
TaskLib's kind of borderline - I'll ditch it if I decide it doesn't add
sufficient value over what currently exists, but it'd be nice to get a
decent prototype working first so I can properly judge it.)
>> Is there a way to convert a script object to an
NSAppleEventDescriptor of typeScript? (Other than packing it into an
AppleEvent and sending it to a custom-installed AE handler, which is a
chore.)
>
> Use NSArray's -arrayWithObject: to make a single-item array, then get
its firstObject()?
Nope, ASOC just returns a BAGenericObject instance. Which,
frustratingly, does know the component instance and OSAID for the script
object, and even displays it in its -description method, but if it has
properties for getting these values directly they're not documented AFAIK.
>> (I need a way to do stuff like call OSADisplay to get the
source-code representation of any AS value.)
>
> Good luck with that.
I've done it in the past with an osax: wrap the value in a script object
to preserve its context, then send it to an AE handler which calls
OSALoadExecute and OSADisplay. I'd prefer to avoid an osax this time
(nasty old crap, plus requires separate installation); I could use a
SFBA and tuck that in the library bundle, but it's still a bit kludgy
for my tastes. Or I could probably use NSAppleEventManager to install
an AE handler directly, but that's still kludgy and Murphy's Law means
I'm not overly keen on mucking with host processes' state. (And let's
not even speak of error-block-based hacks.) And ideally I want something
that isn't going to complain when a «class ocid» specifier is passed to
it. If it all gets too intractable, I'll write it off as
another-one-of-those-features AppleScript needs to implement itself, but
if it can be done with current tools then it saves a bunch of bother.
> (You really ought to take time to have a look at ASObjC explorer, you
know...)
Yeah, I'm aware ASOC Explorer has very nice output logging. (And yeah,
it'd be nice if the AS team would just nab it off you - Jon's
Commands-style - and merge its capabilities into SE.) But this is for
the libraries I'm doing, so they need to be free, portable, and
self-contained. And preferably hackery-free (if indeed this is even
possible in AppleScript).
Thanks,
has
_______________________________________________
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