5 Replies Latest reply on Mar 4, 2011 8:18 AM by Michael L Hale

    Pass string to clipboard (javascript)

    Ghoulfool Level 1

      Is there an easy way to pass a variable or string to the Windows clipboard using photoshop javascript without having to write out a textfile and then use clip.exe to copy the contents of that file to windows clipboard? Or is it easily done in Visual Basic (in which case I would nee to alter my script but that's not too bad as it's quite short)

      Cheers

        • 1. Re: Pass string to clipboard (javascript)
          Paul Riggott Level 6

          If you are using CS4 or CS5 this should work...

           

          var string = "This is text for clipboard test";
          system("echo "+ string +"|clip");
          
          • 2. Re: Pass string to clipboard (javascript)
            Ghoulfool Level 1

            Sadly no; using CS2

            System is not a function

            • 3. Re: Pass string to clipboard (javascript)
              Michael L Hale Level 5

              In CS2 you should be able to write a temp bat file for your Exentdscript that does the same thing as Paul's system call and then run the bat file with file.execute() then remove the bat file.

               

              It's more work than using system but can be done.

              • 4. Re: Pass string to clipboard (javascript)
                Ghoulfool Level 1

                Something like this? Only clipe.exe doesn't get shipped with XP

                 

                copyTextToClipboard(str)

                 

                function copyTextToClipboard(text)
                {
                   var folderForTempFiles = Folder.temp.fsName;

                 

                   // create a new textfile and put the text into it
                   var clipTxtFile =new File(folderForTempFiles + "/ClipBoard.txt");
                   clipTxtFile.open('w');
                   clipTxtFile.write(text);
                //  clipTxtFile.close();

                 

                   // use the clip.exe to copy the contents of the textfile to the windows clipboard
                   var clipBatFile =new File(folderForTempFiles + "/ClipBoard.bat");
                   clipBatFile.open('w');
                   clipBatFile.writeln("cat \"" + folderForTempFiles + "/ClipBoard.txt\"|clip");
                   clipBatFile.close();
                   clipBatFile.execute();
                }

                • 5. Re: Pass string to clipboard (javascript)
                  Michael L Hale Level 5

                  Ghoulfool wrote:

                   

                  Something like this? Only clipe.exe doesn't get shipped with XP

                  Yes, you will have to get clip from another system that has it or a non Mircosoft replacement. You can find one doing a Google search.

                   

                  And I was thinking more along the lines of the code below. It only needs one temp file.

                  var str = "text to clipboard";
                  copyTextToClipboard(str)
                  
                  function copyTextToClipboard(text){
                     var folderForTempFiles = Folder.temp.fsName;
                     var clipBatFile =new File(folderForTempFiles + "/ClipBoard.bat");
                     clipBatFile.open('w');
                     clipBatFile.writeln("echo "+text+" | clip");
                     clipBatFile.close();
                     clipBatFile.execute();
                     clipBatFile.remove();
                  };