deek5 deek5 - 11 months ago 67
AppleScript Question

How to use applescript scripts in Objective-C without deploying all the arsenal cocoa and framework?

I would like to have applications compiled with Xcode directly in C without having to use all the libraries cocoa framework. Applications that remain light.

Answer Source

You're gonna be out of luck, because even if you look at the header for NSAppleScript, you can already see that the class references a lot of other classes in Cocoa (Technically Foundation)

What you could do is just include Foundation, which is a sub-framework of Cocoa.

In fact, if you just look at the header for Cocoa, you will see these 3 lines:

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import <CoreData/CoreData.h>

Then to use NSAppleScript, is very simple:

   NSString* applescript = @"tell application \"Microsoft Excel\" \n"
      @"activate \n"
      @"set scroll row of active pane of active window to 1 \n"
      @"end tell";

   NSAppleScript* script = [[NSAppleScript alloc] initWithSource:appleScript];
   NSDictionary* errInfo = nil;
   return [script executeAndReturnError:&errInfo];

EDIT: Here is another SO answer with a script that converts applescript into a string you can use as the argument to -initWithSource:
Change Applescript into single line NSApplescript source