Re: Faceless background app that uses NSAppleScript
Re: Faceless background app that uses NSAppleScript
- Subject: Re: Faceless background app that uses NSAppleScript
- From: has <email@hidden>
- Date: Thu, 16 Oct 2008 21:36:56 +0100
Scott Ribe wrote:
I need to write an app whose purpose is to drive other apps, using
NSAppleScript. No UI is needed. But I'm unclear on what kind of
environment
needs to be set up in order for NSAppleScript to work. I suspect it
needs at
least NSRunLoop event processing; I wonder if it might also need an
NSApplication around.
Installing Apple event handlers that receive incoming events from
other processes requires an event loop, of course, but I'm not aware
of any limitations in NSAppleScript or the AppleScript component that
force you to create one for outgoing events.
You certainly don't need an event loop to use AESend() or
AESendMessage() unless you want to receive replies asynchronously.
I've written scads of event loop-less Python/Ruby/ObjC code that uses
both of these APIs synchronously. I've also written the occasional
Python shell script to run AppleScripts via the Carbon OSA or Cocoa
NSAppleScript APIs without problems.
FWIW, I think the AppleScript component may require a Window Manager
connection, but you're unlikely to be running it in an environment
without WM access anyway (as scriptable desktop applications
invariably require WM access as well).
Past use of NSAppleScript has revealed that it's somewhat "quirky"
about
event handling, in that what looks like a blocking synchronous call
(executeAndReturnError), seems to allow the event loop to keep
processing
while it's waiting for a response.
I don't think so - AppleScript is normally used on the main thread on
account of it being a PITA to use anywhere else, and anything running
on your main thread will block your event loop until it returns.
(There is an ancient and convoluted mechanism in AESend() from pre-OS
X days that allows it to yield to other routines while waiting on a
response, but let's not go there.)
You could also try asking on the applescript-users or applescript-
implementors mailing lists; someone like Chris Nebel (AppleScript
engineer) could tell you for sure what AS's limitations are.
HTH
has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden