Re: The Future (ASS, ASOC, Cocoa + AS)
Re: The Future (ASS, ASOC, Cocoa + AS)
- Subject: Re: The Future (ASS, ASOC, Cocoa + AS)
- From: has <email@hidden>
- Date: Fri, 30 Apr 2010 22:38:04 +0100
Hagimeno wrote:
> after many years of ASS (since the beginning) we need to learn the new ASOC.
> Is better to learn ASOC or learn Cocoa and interact with apps using AppleScript?
I think you're confusing Cocoa with Objective-C. Cocoa is a collection of frameworks (libraries) that provide lots of functionality for building Mac applications. Objective-C and AppleScript are programming languages, and both can access the Cocoa frameworks (ObjC directly; AppleScript via the ASOC bridge). Regardless of whether you use AppleScript or ObjC, you have to learn the Cocoa frameworks.
(In practice, you will find that you need to pick up a little ObjC knowledge as well, if only so that you can understand Cocoa documentation and example code. Not enough to write it fluently, but enough to be able to read it when you see it and translate it to its AS equivalent for yourself.)
> We need, like in ASS, create Apps that use much interaction with standard Apps (Photoshop, InDesign...).
> Is possible using Cocoa to invoke AppleScript? We think yes but this is robust implementation or is complicated?
I would stick with AppleScript for this. Apple's Scripting Bridge is inferior to AS; the API is obfuscated and confusing, and it's prone to application compatibility and performance problems. ObjC appscript is better, but it's still more verbose and not quite as polished as AS.
(Personally, I find objc-appscript fine for doing modest amounts of application scripting in larger ObjC-based apps, but all of my heavy-duty automation development using Python and py-appscript, which is more like AS in terms of compactness, readability, and speed of development. Incidentally, I've started putting browser-based UIs on my workflows, rather than GUIs or CLIs, which is very easy to do in Python and Ruby - another option you might consider if your systems are server-based.)
> I mean more complicated that do this in ASS or ASOC.
> There is an example of AS routine invoked by Cocoa app?
> Just a short example that explain how to pass parameters and how the result are returned to Cocoa app.
I've not tried it myself yet, but I expect you can use ASOC within larger ObjC-based applications to implement your application scripting-related 'classes' as AppleScript script objects which your ObjC code can send messages to just as it would to ObjC-based classes. Unlike ASS, which provides only one-way access from AS to ObjC, ASOC is a two-way bridge (albeit with a few limitations) so AS can talk to ObjC code _and_ vice-versa.
However, if the main purpose of your applications is to script other applications then I would recommend writing them in AppleScript using ASOC and only writing ObjC code when you need to access functionality that can't be reached via the ASOC bridge.
If you really want to see what application commands look like in ObjC syntax, I suggest grabbing a copy of ASTranslate from the appscript website and running some AppleScript-based application commands in it. (ASTranslate is self-contained; you don't need appscript in order to play with it.) For example:
tell application "Finder"
move every file of desktop to folder "Documents" of home
end tell
translates to:
#import "FNGlue/FNGlue.h"
FNApplication *finder = [FNApplication applicationWithName: @"Finder"];
FNReference *ref = [[finder desktop] files];
FNMoveCommand *cmd = [[ref move] to: [[[finder home] folders] byName: @"Documents"]];
id result = [cmd send];
which is a straight conversion of the Apple event sent by the AppleScript. You can use it as a starting point in your own code - cleaning it up, modifying it, and adding error handling as needed - or just play with it to get a feel for appscript syntax.
HTH
has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net
_______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden