I had the same problem recently as well. I "fixed" it by still using the action api with OpenDocument
but then waiting for a little:
export function OnOpenDocument() {
setTimeout(function () {
var UI = require('sketch/ui')
var document = require('sketch/dom').getSelectedDocument()
UI.alert("Path of this document", String(document.path))
}, 1);
}
You can read more about the JavaScript SetTimeout
function here.` It's definitely no good coding style – but it works for my purpose.