0

Writing JXA automation script that executes function of application.

var app = Application('Pages')
var doc = app.open(new Path('path to file'))
app.export(doc, {
        to: new Path('path to file'),
        as: dstFormat,
        withParameters: params
    })

app.export function sometimes trows error message box. When that message box is thrown script execution stops. How automatically close that message box?

Jonas
  • 4,683
  • 4
  • 45
  • 81

1 Answers1

0

If the error results from a 'path not found' case, you could precede app.open with a defensive check:

// doesFileExist :: FilePath -> IO Bool
const doesFileExist = strPath => {
    const ref = Ref();
    return $.NSFileManager.defaultManager
        .fileExistsAtPathIsDirectory(
            $(strPath)
            .stringByStandardizingPath, ref
        ) && ref[0] !== 1;
};
houthakker
  • 688
  • 5
  • 13