I am working on a modified version of @jessegrosjean’s script here.
Instead of incrementing/decrementing a start date, I am wanting a script to just set the start date to a date from a variable defined outside of the TaskPaper function. I am running into a problem.
This codes works (selectedDate variable defined locally in the TaskPaper function):
function TPContextGetCurrentPath(editor, options) {
var selection = editor.selection;
var selectedItems = selection.selectedItems;
var selectedDate = "2000-12-17";
editor.outline.groupUndoAndChanges(function() {
selectedItems.forEach(function(each) {
var attributeName = 'data-' + options.tag;
var dueDate = each.getAttribute(attributeName);
each.setAttribute(attributeName, selectedDate);
});
});
editor.moveSelectionToItems(selection);
}
var path = Application("TaskPaper").documents[0].evaluate({
script: TPContextGetCurrentPath.toString(),
withOptions: {
tag: 'start'
}
});
But this does not work (selectedDate variable defined globally outside the TaskPaper function):
var selectedDate = "2000-12-17";
function TPContextGetCurrentPath(editor, options) {
var selection = editor.selection;
var selectedItems = selection.selectedItems;
editor.outline.groupUndoAndChanges(function() {
selectedItems.forEach(function(each) {
var attributeName = 'data-' + options.tag;
var dueDate = each.getAttribute(attributeName);
each.setAttribute(attributeName, selectedDate);
});
});
editor.moveSelectionToItems(selection);
}
var path = Application("TaskPaper").documents[0].evaluate({
script: TPContextGetCurrentPath.toString(),
withOptions: {
tag: 'start'
}
});
On the face of it, it seems like a scope problem, but I would think the function in the second script would inherit the variable declared globally. What am I missing here?