Hello,
I'm trying to run a batch sequence that automatically finds a cover file and inserts it as the first page of a document. I'm doing this assuming that filenaming conventions have been followed, so to build in a failsafe for the script I have tried to allow the user to select the file using browseForDoc if the file is not found.
The code works as expected from the console, but won't run from a batch process - browseForDoc generates a NotAllowedError. Any ideas why? I have done some brief testing calling browseForDoc as a trusted function, which i think will work but I'd love to understand why it won't work from a batch normally.
I've inserted my code below:
global.sWorkingPath = (this.path); global.setPersistent("sWorkingPath",false); global.sIdealCoverPath = this.path.replace("-text-working","-cover-working"); global.setPersistent("sIdealCoverPath",false); //Get the name of the current file, assume it ends with "text-working.pdf" //and try to rename it to "cover-working.pdf" so the cover file can be inserted. /* Now test the filename to see if the cover can be inserted automatically, on error, prompt user to select file*/ /* The var global.sIdealCoverPath specifies the cover file to be inserted.*/ console.println("Attempting to automatically insert cover file for " + this.documentFileName); var bCoverInserted = 0; //this variable will be switched to 1 if the cover is inserted successfully to skip further attempts at insertion that occur later in the script. /* Now check that the rename has in fact changed the filename. If the rename has failed, throw an exception because the next step will fail without a correctly named file.*/ try { if (this.path == global.sIdealCoverPath) throw "Cover file for " + this.documentFileName + " not found.\n Please ensure you follow the file naming guidelines, " + "using '-text-working.pdf' and '-cover-working.pdf'.\n You will now be directed to select the cover file manually."; } catch(e) { //alert the user to the problem, prompt them to insert the file, then run a script saving the file as ebook-working.pdf app.alert(e); //get the user to browse for the cover file, then use that information to insert that cover into the current document try { var oBrowseForCover = app.browseForDoc({bSave: false, cFilenameInit: "",cFSInit: "",}); if ( typeof oBrowseForCover != "undefined" ) for ( var o in oBrowseForCover ) console.println( "oBrowseForCover." + o + "=" + oBrowseForCover[o]); else {console.println("User cancelled browsing for cover!"); event.rc = false;} } catch(e) { console.println(e) for (var i in e) console.println( i + ": " + e[i]) }
app.browseForDoc({bSave: false, cFilenameInit: "",cFSInit: "",});
You need to remove the last comma. Also, I think you should not specify cFilenameInit as an empty string. It might also cause a problem.
- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com