Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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