Has anyone had luck with sharing code between scripts? I have some functions I would like to create once and share across scripts so that they don’t get out of sync with copy/pastes. I have read all the Applescript docs on how to create Library functions, and I can get them to work in the global context, but they never return when called inside of a TP script/Anonymous function.
// works in global context
var app = Application(“TaskPaper-compiled”); //only works when compiled !?!
const calculatedPriority = tp.calculatePriority(item);
…
// does not work in TPContext:
(function () {
function TaskPaperContext(editor, options) {
var app = Application(“TaskPaper-compiled”); //only works when compiled !?!
const calculatedPriority = tp.calculatePriority(item);
…
Very cool…functional programming at its finest…took me a bit to figure it out, but I think I got it now. However, when trying to execute the code by itself with one file and no code added, here’s what I get:
execution error: Error on line 37: TypeError: undefined is not an object (evaluating ‘global.TYPED_ARRAY_SUPPORT’) (-2700)
The kind folks on the Web forums of the world point to that error being a babel issue and say to remove “env” from “presets”. Not sure how that applies here in the world of JXA. Any ideas?
Thank you. I am not using babel – that’s just what people on the Internet says causes this error. I am just running the importing template code you pasted above as JXA from VSCode (osascript…) without any changes other than specifying an empty (or basic JS) file where the file path strings are. That should work, right? Does that template run for you as is?