5 Replies Latest reply on Sep 30, 2015 8:20 AM by JJMack

    Need a java script to run a hyperlink through photoshop actions

    Sivabalan1989

      I need a script which takes a part of its file name and creates a hyperlink out of it and opens in a browser. For example file name is : 1234567890.BZJSH62893.TEAR.jpg   It should take only the middle part of the file name and concatenate with " www.xxxxxx.com\yy\partoffilename".

        • 1. Re: Need a java script to run a hyperlink through photoshop actions
          try67 MVP & Adobe Community Professional

          [Question moved to the PS Scripting forum]

          • 2. Re: Need a java script to run a hyperlink through photoshop actions
            JJMack Most Valuable Participant

            A script can do that however the browser would get and error it the JPEG is not in the Web servers folder yy.  Most Web servers also run on unix systems. Unix file system is cams sensitive.  You must the document name must have the correct  name and case and the file extension suffix must also be correct and have the correct case.  The path yy must also be the correct case.

             

            You shoul be able to  modiy this script code..

             

             

            function openInBrowser(/*str*/url) {
                var    f = new File(Folder.temp.absoluteURI + '/url_' + (+new Date()) + '.url' );
                var fStr = "[InternetShortcut]\rURL="+url;
            
            
                f.open('w');
                f.write(fStr);
                f.close();
                f.execute();
                f.remove();
            }
            
            
            // Test:
            var docName = app.activeDocument.name;
            openInBrowser("http://www.xxxxxx.com/yy/" + docName + ".jpg");
            
            • 3. Re: Need a java script to run a hyperlink through photoshop actions
              xbytor2 Level 4

              My version of this is slightly different. In order to get this to work on both OS X and Windows, I had to add a blank line at that end.

               

              function openURL(url) {

                var fname = "shortcut.url";

                var shortcut = new File(Folder.temp + '/' + fname);

                shortcut.open('w');

                shortcut.writeln('[InternetShortcut]');

                shortcut.writeln('URL=' + url);

                shortcut.writeln();

                shortcut.close();

                shortcut.execute();

                shortcut.remove();

              };

              • 4. Re: Need a java script to run a hyperlink through photoshop actions
                Sivabalan1989 Level 1

                Thanks for the Script . It is working. But It takes the entire document name. I need only the middle part. For example if we have a file named 75045967.B00E589FZE.MAIN. The script should take only the middle part "B00E589FZE". So that it will go to the description page. For example "www.yyyyyy.com/dp/B00E589FZE" .  It will make my work a lot easier. Because every time i have to copy that part of file name and go to the address bar and paste it to see the description. Thank you once again.

                • 5. Re: Need a java script to run a hyperlink through photoshop actions
                  JJMack Most Valuable Participant

                  Then change the script to do that.  You must come up with a way to split the name up. You need to define what middle is and pull out that middle part of the nane string.  It should be very easy if the length of the of the part are always the same.  If the length varies you need to have some way to find out the length of the parts.

                   

                  The front part looks like it may be delimited by the "." however I see no delimiter  between the "E" and "MAIN"....

                   

                  Oh I see it now my old eyes though repaired with new lenses are not as good as they use to be.  The change show be easy to make. Try it.

                   

                   

                  hint

                   

                  midPart = docName.substr(docName.indexOf(".") + 1,docName.length); //Strip front part

                  midPart = midPart.substr(0,midPart.indexOf("."));                                   //keep mid part