9 Replies Latest reply on Oct 20, 2014 12:20 PM by iamwickedtall1

    How do I make a loader image similar to those shown at program opening?

    iamwickedtall1 Level 1

      I'm looking to build a loader image, that opens up at the start of my script, and automatically closes after a few seconds. I opened up the image processor script to see how Adobe has added images to alerts, but it's an extensive doc, and I couldn't tell where the image was being pulled from, as the variable only shows up twice, and is only called, and not set. Also is there another method other than alert to call a box like this? I would prefer it have no buttons.

        • 1. Re: How do I make a loader image similar to those shown at program opening?
          xbytor2 Level 4

          This script shows how to open a ScriptUI dialog and populate it with an image.

          http://ps-scripts.cvs.sourceforge.net/viewvc/ps-scripts/xtools/xlib/PreviewWindow.jsx

           

          It, however, has a 'Close' button required to close the window. If you want to automatically close the dialog

          after a set period of time, you will need to change openFile to something like this:

           

          var sleepMS = 3000;  // how long to sleep in milliseconds

           

          PreviewWindow.openFile = function(file, w, h, parent, title) {
            var win = new Window('palette', title || "Preview: " + decodeURI(file.name));
            win.closeBtn = win.add('button', undefined, 'Close');

            win.preview = win.add('image', undefined);
            win.preview.icon = file;

            if (w && h) {
              win.preview.preferredSize = [w, h];
            }

            if (parent) {
              win.center(parent);
            }

            win.closeBtn.onClick = function() {
              this.parent.close(1);
            }

            win.show();

            $.sleep(sleepMS);

            win.close();
            delete win;
            $.gc();
          };

           

          // example usage

          PreviewWindow.open("~/tmp/preview.jpg");

           

          I haven't tried this code out but it looks pretty close.

          • 2. Re: How do I make a loader image similar to those shown at program opening?
            xbytor2 Level 4

            I just uploaded a version of this script that fixes a couple of latent bugs.

            • 3. Re: How do I make a loader image similar to those shown at program opening?
              iamwickedtall1 Level 1

              Awesome script!! Any chance it can be done without the frame and close button? I'm assuming that kind of access isn't given to extend script, but I'm also thinking of displaying a quick success sprite image when my script runs successfully.

              • 4. Re: How do I make a loader image similar to those shown at program opening?
                xbytor2 Level 4

                Remove these lines

                win.closeBtn = win.add('button', undefined, 'Close');

                 

                and

                  win.closeBtn.onClick = function() {

                    this.parent.close(1);

                  }

                 

                to get rid of the Close button.

                 

                You can get rid of the border by making this change:

                  var win = new Window(type, title || "Preview: " + decodeURI(file.name),

                                                       undefined, { borderless : true });

                 

                -X

                • 5. Re: How do I make a loader image similar to those shown at program opening?
                  iamwickedtall1 Level 1

                  I was able to boil your script down, to what I need. Works great in extendscript, but for some reason, only shows a portion of the image in photoshop and illustrator. This was happening even before i boiled it down. Thoughts? The last thing I'm trying to do with it, is figure out if I can set a transparent background for the window. I also tried using backgroundColor, but was unable to set the attribute correctly... there is a lot to learn with Adobe scripting. I also couldn't find reference to what DELTA_H is, I have a bunch of their PDFs, and googled, but couldn't find reference to this. I'm trying to be resourceful so I don't have to ask such remedial questions.

                   

                  Here's the revised script, and a link to the image I labelled test on my desktop: http://img2.wikia.nocookie.net/__cb20110725041802/logopedia/images/8/89/Logo_rolling_stone s.png

                  PreviewWindow = function() {

                  };

                   

                  w = 285;

                  h = 313;

                  PreviewWindow.DELTA_H = 1;

                   

                  PreviewWindow.open = function(file, w, h, title, ms) {

                    PreviewWindow.openFile(file, w, h, title, ms);

                  };

                   

                  PreviewWindow.openFile = function(file, w, h, title, ms) {

                    var type = (ms > 0) ? 'palette' : 'dialog';

                    var win = new Window(type, title || "Preview: " + decodeURI(file.name),undefined,{borderless : true});

                    win.preview = win.add('image', undefined);

                    win.preview.icon = file;

                   

                    win.show();

                    if (ms > 0) {

                      $.sleep(ms);

                    }

                   

                    delete win;

                    $.gc();

                  };

                   

                   

                    PreviewWindow.open("~/Desktop/test.png", undefined, undefined,

                                       "Preview Test", 500);

                  • 6. Re: How do I make a loader image similar to those shown at program opening?
                    xbytor2 Level 4

                    I was able to boil your script down, to what I need. Works great in extendscript, but for some reason, only shows a portion of the image in photoshop and illustrator. This was happening even before i boiled it down. Thoughts?

                     

                    ScriptUI does not behave consistently across CS apps or CS versions. It's just the nature of the beast. I use PSCS6/Mac as my canonical platform as things tend to work a bit better there than elsewhere. You can always restart/reboot/reset-preferences to see if that cleans things up.

                     

                     

                    The last thing I'm trying to do with it, is figure out if I can set a transparent background for the window. I also tried using backgroundColor, but was unable to set the attribute correctly...

                     

                    I do not think you will be able to do this.

                     

                     

                    there is a lot to learn with Adobe scripting.

                     

                    Agreed. And I've been doing this for nearly 10 years, now.

                     

                     

                    I also couldn't find reference to what DELTA_H is, I have a bunch of their PDFs, and googled, but couldn't find reference to this. I'm trying to be resourceful so I don't have to ask such remedial questions.

                     

                    DELTA_H was a variable that I added to the script to prevent the preview image from taking up the entire screen. Since you aren't using the computations where that's needed, you can safely ignore it.

                    • 7. Re: How do I make a loader image similar to those shown at program opening?
                      iamwickedtall1 Level 1

                      Ahhhh... thanks for all this help! Makes sense about DELTA_H, I should probably do a deep dive on javascript syntax, it gets to me since everything can be separated by ".", but can be set variables or existing parts of the object. I guess they're somewhat the same, but it's helpful to learn the distinction between all. And more importantly, I need to learn the words to describe all these items, because I sound like an idiot.

                       

                      I tested the script on my mac after I mentioned the window not showing up properly, and it turns out it is just a problem with this crappy programming PC I'm on.

                       

                      No big deal on the transparent part, but out of curiosity, there's no other way to have an image show up, except in the window, correct? Additionally, your script is helping me achieve another feature, which is playing a sound at the end of my script. Although I've reached out and there were examples of how to play using media player, I was successfully able to embed a sound in a swf, and it executes just as I would like, by adding:

                       

                      win.preview = win.add ('flashplayer',undefined,'~/Desktop/test.swf');

                       

                      Although, I tried to do a relative path from the script to the sound in the 3rd parameter and was unsuccessful. Is there a simple way of doing this? Or would I have to have a script look up the location of the script I'm running, and then add the "relative" path to this?

                       

                      Thanks again!

                      • 8. Re: How do I make a loader image similar to those shown at program opening?
                        xbytor2 Level 4

                        No big deal on the transparent part, but out of curiosity, there's no other way to have an image show up, except in the window, correct?

                         

                        For ScriptUI, this is correct. There are other UI frameworks (Flash panels, HTML panels) that are available, but I haven't even looked at them in years.

                         

                        win.preview = win.add ('flashplayer',undefined,'~/Desktop/test.swf');

                         

                        Although, I tried to do a relative path from the script to the sound in the 3rd parameter and was unsuccessful. Is there a simple way of doing this? Or would I have to have a script look up the location of the script I'm running, and then add the "relative" path to this?

                         

                        To do it relative to the script, you would need to use (File($.filename).parent + "/test.swf") as the third parameter.

                        • 9. Re: How do I make a loader image similar to those shown at program opening?
                          iamwickedtall1 Level 1

                          Thanks so much! You're a lifesaver! If I do find that the other frameworks achieve what I'm looking for, I'll be sure to post the code.