3 Replies Latest reply on Oct 28, 2015 10:20 PM by JJMack

    Is it possible to call server URL from photoshop script?

    tvstephen7

      I want to send some data to server URL and get response from photoshop, Is there any option to do this?

        • 1. Re: Is it possible to call server URL from photoshop script?
          37105686 Level 1

          you need photoshop to tell you it sent the information, or your looking to pull that information back into photoshop?

          • 2. Re: Is it possible to call server URL from photoshop script?
            xbytor2 Level 4

            Look into wget or curl. These are command line programs that can be called like this:

               app.system("wget http://comsite.org/images/image.jpg > ~/Desktop/image.jpg");

             

            This definitely works on OS X and there is probably something similar available for Win.

            • 3. Re: Is it possible to call server URL from photoshop script?
              JJMack Most Valuable Participant

              I have downloaded images from a web server using socket code I found in Adobe sample Photoshop Javascript Socket.jsx. It seem to use Browser HTML Protocol port 80 GET. But I have never tried FTP a file to a web server using port 21. It would be complex and require a login etc.  There is also a HTML Port 80 PUT  command but I would know how to use that. Hypertext Transfer Protocol - Wikipedia, the free encyclopedia

              // Copyright 2007.  Adobe Systems, Incorporated.  All rights reserved.

              // This script demonstrates how to download images from a web server using the Socket object.

              // Note: Socket.read() parameter & behavior

              // Socket.read() will read or time out. It may not read all data from server.

              // Socket.read(999999) will read 999999 bytes, or timeout, or socket will be

              // closed by the server.

              // Settings

              #target photoshop

              app.bringToFront(); // bring top

              if("en_US" == $.locale) { // display only US build

                alert("This sample script shows how to download images from a web server using the Socket object.");

              }

              // Remove header lines from HTTP response

              function removeHeaders(binary)

              {

                var bContinue = true ; // flag for finding end of header

                var line = "";

                var nFirst = 0;

                var count  = 0;

                while (bContinue) {

                line = getLine(binary) ; // each header line

                bContinue = line.length >= 2 ;  // blank header == end of header

                nFirst = line.length + 1 ;

                binary = binary.substr(nFirst) ;

                }

                return binary;

              }

              // Get a response line from the HTML

              function getLine(html)

              {

                var line = "" ;

                for (var i = 0; html.charCodeAt(i) != 10; i++){ // finding line end

                line += html[i] ;

                }

                return line ;

              }

              var socket = new Socket;

              var html = "";

              if (socket.open("www.adobe.com:80")){

                socket.write("GET /index.html HTTP/1.0\n\n");

                html = socket.read(9999999);

                socket.close();

              }

              var aImg = html.match(/src=\"\/images\/(.*?)\"/g);  //  src="/images/~~~"

              if (null != aImg) { // parsed image tags

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

                try{

                var str = aImg[i];

                var sImg = str.substring(5, str.length-1); // remove "src=" & ["]

                var f = File("~/socket_sample_" + i + sImg.substr(sImg.length-4)); // 4 = .gif or .jpg

                f.encoding  = "binary";  // set binary mode

                f.open("w");

                if (socket.open("www.adobe.com:80", "binary")){

                socket.write("GET " + sImg +" HTTP/1.0\n\n"); // Adobe's site image link starts with "/"

                var binary = socket.read(9999999);

                binary = removeHeaders(binary);

                f.write(binary);

                socket.close();

                }

                f.close();

                app.open(f); // Open files in Photoshop

                f.remove();  // Remove temporary downloaded files

                }catch(e){

                }

                }

              }