Skip to content

Instantly share code, notes, and snippets.

@thesubtlety
Created September 30, 2022 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thesubtlety/4d369127773fe45d69c65852faaa7548 to your computer and use it in GitHub Desktop.
Save thesubtlety/4d369127773fe45d69c65852faaa7548 to your computer and use it in GitHub Desktop.
Obj JXA runner
#import <Foundation/Foundation.h>
#import <Appkit/AppKit.h>
#import <CoreFoundation/CoreFoundation.h>
#import <OSAKit/OSAKit.h>
#import <Cocoa/Cocoa.h>
#import <OSAKit/OSALanguage.h>
#import <Foundation/NSString.h>
#include <string.h>
//jxarunner file.js
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *filepath = [NSString stringWithFormat:@"%s", argv[1]];
//NSLog(@"Got: %@", filepath);
NSFileManager *filemgr;
NSData *databuffer;
filemgr = [NSFileManager defaultManager];
databuffer = [filemgr contentsAtPath: filepath ];
NSString *code = [[NSString alloc] initWithData:databuffer encoding:NSASCIIStringEncoding];
//NSLog(@"Contents: %@", code);
OSALanguage *lang = [OSALanguage languageForName:@"JavaScript"];
OSAScript *script = [[OSAScript alloc] initWithSource:code language:lang];
NSDictionary *__autoreleasing compileError;
NSDictionary *__autoreleasing runError;
[script compileAndReturnError:&compileError];
NSAppleEventDescriptor *res = [script executeAndReturnError:&runError];
//NSLog(@"compileError: %@", compileError);
//NSLog(@"runerr: %@", runError);
NSLog(@"res: %@", res);
return 0;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment