Accessing script run handler from NSAppleScript
Accessing script run handler from NSAppleScript
- Subject: Accessing script run handler from NSAppleScript
- From: "email@hidden" <email@hidden>
- Date: Fri, 4 Jan 2008 20:56:27 +0000
Hi
I am trying to call as wide as possible a variety of AppleScripts from
cocoa using NSAppleScript and am having trouble
finding a way of calling a script with a parameterised run handler.
eg: a script called beepn.scpt and containing
on run (n, interval)
repeat n times
beep
delay interval
end repeat
end run
can be executed from the terminal as:
osascript beepn.scpt 2 1
As yet I have been unable to call such a script from NSAppleScript.
So far my approach has been.
1. If the script has no specified run handler or a run handler without
parameters then
use the NSAppleScript - executeAndReturnError method.
This works for scripts such as:
beep
or
on run
beep
end run
2. if the script contains a specified handler then I construct an
NSAppleEventDescriptor
specifying the handler and parameters and call the NSAppleScript
- executeAppleEvent method.
This works for scripts such as:
on beep(n, interval)
repeat n times
beep
delay interval
end repeat
end beep
Unfortunately neither of these methods can handle a script with run
handler parameters.
Calling NSAppleScript -executeAndReturnError gives no output - as may
be expected.
Calling the run handler explicitly by name with NSAppleScript -
executeAppleEvent results in:
Error -1708 occured the run(Hello) call: (null)
which evaluates to errAEEventNotHandled -1708 Event wasnt handled
by an Apple event handler.
Passing an empty or nil handler name also does not work.
Of course I can change the run handler name but that means editing the
script, which I would like to avoid if at all possible.
Any thoughts would be welcome.
_______________________________________________
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