Skip to content

Instantly share code, notes, and snippets.

@surrealroad
Created December 5, 2016 16:10
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 surrealroad/f31527b1e51cb05d532ae4a88f859473 to your computer and use it in GitHub Desktop.
Save surrealroad/f31527b1e51cb05d532ae4a88f859473 to your computer and use it in GitHub Desktop.
JXA Scriptlet to allow importing .js files in the same folder
ObjC.import('Foundation')
var app = Application.currentApplication()
app.includeStandardAdditions = true
var path = app.pathTo(this);
var workflowFolder = $.NSString.alloc.initWithUTF8String(path).stringByDeletingLastPathComponent.js + '/';
//https://github.com/dtinth/JXA-Cookbook/wiki/Importing-Scripts
var jslibPath = workflowFolder + "script.min.js"
var fm = $.NSFileManager.defaultManager;
var contents = fm.contentsAtPath(jslibPath); // NSData
contents = $.NSString.alloc.initWithDataEncoding(contents, $.NSUTF8StringEncoding);
eval(ObjC.unwrap(contents));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment