Re: Running AppleScripts from an App using NSAppleScript
Dave wrote: > I have a number of AppleScripts I’d want to run from my App. Each Script has a couple of parameters [...] Example code here: http://appscript.sourceforge.net/nsapplescript.html The downside (one of them anyway) is that you have to do all of the Cocoa<->AE packing and unpacking yourself. If you're passing complex data, I suggest pinching and adapting the AEMCodecs class from here: https://bitbucket.org/hhas/appleeventbridge/src If the scripts are part of your .app bundle, another option is to use the AppleScript-ObjC bridge, which allows you to call AS handlers directly from ObjC: http://appscript.sourceforge.net/asoc.html It's not perfect - there's no way to declare non-id signatures (you have to wrap and unwrap C primitives yourself) and some of the AE type bridging is problematic (NSDate/typeLongDateTime isn't automatically bridged, and the typeObjectSpecifier mapping is defective), but for most tasks it's the least painful option. HTH has ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Running AppleScripts from an App using NSAppleScript
> On Apr 27, 2015, at 6:52 AM, Dave wrote: > > At the moment, I setup the Text for the Script, Compile it and then Run it > each time. I’m wondering if there is anyway to be able to just compile the > Script once, and then pass the Parameters to the Script as it seems a bit > time-consuming to recompile each time when 99% of the Script is constant. Define an event handler (“on …”) in the script and get the parameters out of it. Then call the script via -executeAppleEvent: passing it an AE descriptor containing the parameter values. —Jens ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Running AppleScripts from an App using NSAppleScript
Hi All, I have a number of AppleScripts I’d want to run from my App. Each Script has a couple of parameters, here is an example: on run set myParam1 to set myParam2 to set myStatus to doStuff(myParam1, myParam2) return myStatus end run — — Do something with Param1 and Param2 — on doStuff(theParam1,theParam2) tell application ”TextEdit" end tell return “OK" end setClassificationContent At the moment, I setup the Text for the Script, Compile it and then Run it each time. I’m wondering if there is anyway to be able to just compile the Script once, and then pass the Parameters to the Script as it seems a bit time-consuming to recompile each time when 99% of the Script is constant. All the Best Dave ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com