I’ve been trying to write some code to download JSON information from remote server and create a Project out of it. Sadly I seem to be tripping right out of the gate…I can’t figure out how to simply create a new document and make it appear.
Here’s what I have so far:
OmniPlan = Application("OmniPlan");
OmniPlan.includeStandardAdditions = true;
//create project, give it a name
var myProject = new OmniPlan.Project();
myProject.title = "My Random Project";
//add to document
var myDocument = new OmniPlan.Document();
myDocument.name = "Bob";
myDocument.project = myProject;
//set as document in window
//though frankly I'd rather just create a new windows and add this document to it.
var window = OmniPlan.windows[0]; //yes, this is sloopy, I'm just prototyping, there's a window open...
window.document = myDocument;
I know that the last line is making the whole thing crash, so I can assume that’s just totally wrong. But using window.add();
or window.document.add();
doesn’t work. Neither does .push for that matter. Besides which I’m not even sure I’m trying to put it in the right place, or if it even can be put!
If anyone can give me some direction? I’m sorry it’s such a n00bish question but…I really just can’t figure out where to go with this… I wish I could find a “getting started” tutorial for Javascript for Automation with Omniplan…
Edit:
Did some further work and found that this procedure works with TextEdit:
app = Application("TextEdit");
app.activate();
myDoc = app.Document();
myDoc.name = "testing";
app.documents.push(myDoc);
And yet this conceptually similar code will not work in OmniPlan:
OmniPlan = Application("OmniPlan");
OmniPlan.activate();
document = OmniPlan.Document();
document.name = "Testing";
OmniPlan.documents.push(document);
But instead gives me the following error in the console:
app = Application("OmniPlan")
app.activate()
Application("OmniPlan").documents.push(app.Document({"name":"Testing"}))
--> Error -10000: AppleEvent handler failed.
Result:
Error -10000: AppleEvent handler failed.
With this pop-up also appearing:
Error on line 6: Error: Instantiating a document with properties {
displayName = Testing;
} resulted in no windows.
Starting to wonder if perhaps this is some sort of bug? Or if there’s just some magical property I’m not setting that needs to be set?