Search code examples
javascriptosx-yosemiteadobe-indesignjavascript-automationadobe-javascript

Moving created files with JXA


I'm new to JXA scripting, but I'm attempting to troubleshoot some older scripts currently in place here at work. They loop through an InDesign document and create several PDFs based on it. Previously, they would be stored in a folder called "~/PDFExports". However, this doesn't work with 10.10.

If I change the code to just place the PDFs in "~/", it works fine. From there, I'd like to move the files to "~/PDFExports", but I can't seem to find an answer on how to do that. I've seen things about making calls to ObjC, or to call Application('Finder'), but neither work - they both return undefined.

Am I just missing something basic here, or is it really this hard to simply move a file with JXA?

EDIT: Some syntax for how I'm creating the folder in question and how I'm attempting to work with Finder.

//This is called in the Main function of the script, on first run.

var exportFolder = new Folder(exportPath);
if(!exportFolder.exists) {
    exportFolder.create();
}

//This is called right after the PDF is created. file is a reference to the 
actual PDF file, and destination is a file path string.

function MoveFile(file,destination){
   var Finder = Application("Finder");

   Application('Finder').move(sourceFile, { to: destinationFolder });

   alert("File moved");
}

Solution

  • Adobe apps have long included their own embedded JS interpreter, JS API, and .jsx filename extension. It has nothing to do with JXA, and is not compatible with it.

    InDesign's JSX documentation:

    http://www.adobe.com/devnet/indesign/documentation.html#idscripting

    (BTW, I'd also strongly advise against using JXA for Adobe app automation as it has a lot of missing/broken features and application compatibility problems, and really isn't fit for production work.)

    Here's the link to Adobe's InDesign Scripting forum, which is the best place to get help with JSX:

    https://forums.adobe.com/community/indesign/indesign_scripting