3 Replies Latest reply on May 4, 2017 4:33 AM by Mahesh_JW

    do scirpt for copy file

    Mahesh_JW

      for(var a=0;a<myDoc.links.length;a++){
             
                  var  f = File(myDoc.links[a].filePath);
                  var fname = f.name;
                
                  copyPasteScript = "tell application \"Finder\"\r";
                 copyPasteScript += "copy file \""+myDoc.links[a].filePath+"\" to folder \""+ArtFolder+"\"\r";
                  copyPasteScript += "end tell";
                  app.doScript(copyPasteScript, ScriptLanguage.applescriptLanguage);
                 
                  var f2 = File(ArtFolder+"/"+fname);
                  myDoc.links[a].relink(f2);
                  myDoc.links[a].update();
      }

       

       

      it throws error in the highlighted line what to do....

        • 1. Re: do scirpt for copy file
          [Jongware]-9BC6tI Level 4

          "An error". Care to tell what the error is? That might help us to help you.

           

          Looking at your script, I would guess "Unknown variable: ArtFolder".

          • 2. Re: do scirpt for copy file
            Muppet Mark-QAl63s Level 4

            Why NOT use ID's links copyLink to folder? No need to involve AppleScript and Finder…

             

            #target indesign

             

            var userHome = Folder('~').fsName.toString();

            var linksFolder = userHome + '/Desktop/ID Links/';

            myLinks = CreateFolder(linksFolder);

             

            main();

             

            function main() {

            if (app.documents.length == 0) {

            alert('Please have an "Indesign" document before running this script.');

            return;

            }

            docRef = app.activeDocument;

            with(docRef) {

            for (var i = 0; i < links.length; i++) {

            links[i].copyLink(myLinks);

            }

            }

            };

             

            function CreateFolder(Directory) {

            var folderPath = new Folder(Directory);

            if (folderPath.exists == false) {

            folderPath.create();

            return folderPath;

            }

            }

            • 3. Re: do scirpt for copy file
              Mahesh_JW Level 1

              var myParameters = [File(myFile),Folder(myFolder)];

               

              //copy

              var myAppleScript = "tell application \"Finder\"\rtry\rcopy file (item 1 of arguments as string) to folder (item 2 of arguments as string)\rend try\rend tell";

               

              //move

              var myAppleScript = "tell application \"Finder\"\rtry\rmove file (item 1 of arguments as string) to folder (item 2 of arguments as string)\rend try\rend tell";