Hi all, new to AppleScript so I figured I’d have more luck with JXA, but it seems even more inscrutible.
Ultimately, I’m trying to make a script that dumps a list of flattened tasks from a perspective in a structured data format (prefereably JSON). I plan to feed this to Alexa so I can have my daily tasks as part of my “flash briefing”.
I am getting stuck on how to flatten and iterate through the contentTree to pull out the individual tasks.
I tried the approach @unlocked2412 suggested in another thread for pulling all the tasks in the database, but it seemed a bit slow and I would rather not duplicate the perspective filters.
Perhaps that is a better approach, since this way changes the perspective in the current window which will be a problem when I’m trying to work and this script runs in the background.
Any thoughts? This is what I have thus far
const myPerspective = "Hot";
var of = Application('OmniFocus');
var ofDoc = of.defaultDocument;
var win = ofDoc.documentWindows.at(0);
var hotContent = win.content();
// writing out as UTF8 using objectiveC bridge
var reportStr = $.NSString.alloc.initWithUTF8String('foo');
reportStr.writeToFileAtomicallyEncodingError('/Users/lambda/alexatest/todo.json', true, $.NSUTF8StringEncoding, null);
Happy to help! In the Utilities folder on your Mac, you’ll find one named Script Editor; go ahead and drop OmniFocus’ app icon onto Script Editor. This will open up a window which shows the AppleScript commands which are available. (You can do this with any app that offers an AppleScript interface; it’s not OmniFocus-specific.)
By what’s in the AppleScript dictionary they don’t seem to, but they functionally do on the watch. My watch face is configured to show me the first task in one of my perspectives (which I have configured to be the task I should probably be working on right now). I’d like to get show that task on my menu bar on my Mac too.