JavaScript for Automation: import CSV and press ok for mapping popup

I try to Open a CSV file (and then Export that one) using JavaScript for Automation (JXA).
Using OmniPlan v2.

When I manually open (import) a CSV file a popup appears to map the columns.
The mapping that is shown is fine, so all I have to do is press OK (or press Enter).

How do I achieve this using JavaScript for Automation?
When I try this the app.open() call is stuck until I manually press ok for the popup.

What I tried:

var systemEvents = Application('System Events')
var app = Application("OmniPlan")
app.open(Path("~/Documents/omniplan_import.csv"))
// popup appears: "Map Columns" ← how to select "OK"?
console.log("import completed") // only reaches this one after manually closing the popup
systemEvents.keyCode(36); // therefore sending Enter keycode has no effect

With the excellent help from Christian (thanks!), this is the workaround we came up with.
Make sure you have Script Editor enabled in System Preferences > Security & Privacy > Accessibility.

var systemEvents = Application('System Events')
var app = Application("OmniPlan")
try {
  // open the CSV (popup appears) and let this timeout after 1 second so we can send Enter
  app.open(Path("/Users/myname/Documents/omniplan_import.csv")), {timeout: 1})
} catch(error) {
  // send Enter (OK) to use the default values and close the popup
  systemEvents.keyCode(36);
}
1 Like