Search code examples
objective-cosx-snow-leopardf-script

How to link an application classes to F-Script


I would like to create a command line application that accepts a script F-Script that is executed, and which has access to some classes exposed by the application.

How can I do that?

PS: I am referring to F-Script, not FScript.


Solution

  • Looking at the code of FScript.app, which is reported to be linked to most of the Core framework, I found the following method:

    - (void)loadSystemFrameworks  // Contributed by Cedric Luthi
    {
      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    
      NSMutableArray *systemFrameworksPaths = [NSMutableArray arrayWithObject:@"/System/Library/Frameworks"];
    
      if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FScriptLoadPrivateSystemFrameworks"])
        [systemFrameworksPaths addObject:@"/System/Library/PrivateFrameworks"];
    
      for (NSString *systemFrameworksPath in systemFrameworksPaths)
      {
        for (NSString *framework in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:systemFrameworksPath error:NULL])
        {
          NSBundle *frameworkBundle = [NSBundle bundleWithPath:[systemFrameworksPath stringByAppendingPathComponent:framework]];
          if ([frameworkBundle preflightAndReturnError:nil])
            [frameworkBundle load];
        }
      }
    
      [pool drain];
    }
    

    I take that to link to the classes defined from an application is enough to load the bundle containing the classes.