19 Replies Latest reply on Feb 10, 2011 1:36 AM by Pontus Uggla

    Refresh window

    Pontus Uggla

      Is there a way to refresh a window/dialog.


      I have a script that i trigger from a menu, with a progress bar, but the window wont do anything in CS5, it works fine in CS4.


      Harbs? Anyone?

        • 1. Re: Refresh window
          Harbs. Level 6




          • 2. Re: Refresh window
            Pontus Uggla Level 1

            I guess that updates the window with the document, I ment the window that I created with new Window().


            Here is my script, it works great in CS4 but not in CS5.


            #targetengine "session"
            // Create menu item
            var test_menu = app.menus.item('$ID/Main').submenus.add('Test menu');
            // Create sub menu action
            var test_sub_menu = app.scriptMenuActions.add('Run progressbar');
            // Set on invoke action
            test_sub_menu.eventListeners.add('onInvoke', function() {
                 // Create a simple window
                 var win = new Window(
                      "window { \
                           progressbar: Progressbar { size: [400, 10] } \
                 // Center and show the window
                 // Set max value for the progressbar
                 win.progressbar.maxvalue = 5;
                 // Make a simple loop from 0 to 4
                 for(var i = 0; i < 5; i++) {
                      // This should happen every second
                      win.progressbar.value = i;
                      // Sleep for a second
                 // Remove the test menus actions
                 app.scriptMenuActions.item('Run progressbar').remove();
                 // Remove the test menu
                 app.menus.item('$ID/Main').submenus.item('Test menu').remove();
            // Add the sub menu action

            • 3. Re: Refresh window
              Harbs. Level 6



              win.progressbar.value = i;


              should do it...

              • 4. Re: Refresh window
                Pontus Uggla Level 1

                It should, but nothing happens.


                Can you see anything wrong with this code, as I said it works with CS4.


                This or any other way of reaching something similar?


                I can write to the console, that works fine, but the progressbar or a static text wont work unless i stop it, then it jumps to where it should be.


                This is very frustrating.

                • 5. Re: Refresh window
                  Harbs. Level 6

                  That's odd.


                  update() works for me every time (in every version)...



                  • 6. Re: Refresh window
                    Pontus Uggla Level 1

                    I dont need to update the dialog in CS4, and i dont know why i should 

                    have to in CS5, but it feels like it gets stuck.


                    Have you triggerd progressbars from a menu item in CS5. It seems to me 

                    that it is a bug in InDesign, but I hope it is possible some how. The 

                    script can take 20 minutes, building a catalog, and its good to see 

                    what is going on.


                    Did you try my script? I think it is harmless.

                    • 7. Re: Refresh window
                      Harbs. Level 6

                      HI Pontus,


                      I just tried your script, and I think it's connected to a bug I myself experienced. Did you try creating your menu item in a standard "Main" menu? I have a feeling it's because you are running it from a custom menu.


                      One thing you can try:


                      1) Create you palette in a saved script.

                      2) In your onInvoke function create a BridgeTalk function.

                      3) Target InDesign in BridgeTalk and use doScript to run the saved script.


                      Kind of convoluted, but based on my experience with a simiar bug, it should work...



                      • 8. Re: Refresh window
                        Pontus Uggla Level 1

                        This was the kind of answer I was looking for. I never used BridgeTalk, but this is what I came up with:


                        test_sub_menu.eventListeners.add('onInvoke', function() {
                             myfile = new File(script_path + 'test.js');
                             var src = myfile.read();
                             var bt = new BridgeTalk();
                                bt.target = "InDesign";
                             bt.body = src;


                        There is probably an easier way of reading a file, but this works for now. If I put alert('test'); in the file test.js then it works, but if I try to create a window, I get nothing. I tried putting #targetengine "session" in test.js but no difference.


                        Can I set the target engine of the Bridge Talk object?


                        I will keep looking, but help is appreciated.



                        • 9. Re: Refresh window
                          Harbs. Level 6

                          You set the target to InDesign using lowercase letters. (i.e, bt.target = 'indesign';)


                          I don't think it will work the way you have it because I think BridgeTalk runs in the main (non-presistant) engine.


                          Try something like this (untested):


                          var script = "app.doScript(File(" + script_path + "))";

                          bt.target = script;




                          Innovations in Automation

                          • 10. Re: Refresh window
                            Pontus Uggla Level 1

                            I can get an alert to run, but i cant create a window. Its like its not right the right sessionengine, but setting it in the script does not help.


                            This is really frustrating, but I´m glad for the help!

                            • 11. Re: Refresh window
                              Harbs. Level 6

                              Try this to the beginning of the saved script:


                              #targetengine "Pontus"



                              What does the alert say?



                              • 12. Re: Refresh window
                                Pontus Uggla Level 1

                                It says Pontus. If I put it in the test.js it says "main" and if I set #targetengine "session" first it still says "main". This seems to be the problem. Im thinking something like:


                                var bt = new BridgeTalk();

                                bt.target = "indesign";

                                bt.targetEngine = "session";

                                • 13. Re: Refresh window
                                  Harbs. Level 6



                                  The doScript() should run it in the specified engine.


                                  I don't know of a way to run a BridgeTalk in a specific engine.


                                  Try wrapping the doScript() in and eval(). Does that help?



                                  (who's running out of ideas...)

                                  • 14. Re: Refresh window
                                    Pontus Uggla Level 1

                                    I think BridgeTalk needs a string, not evaluated code.


                                    If I start over. We have a database with products and the script gets information and builds/updates catalogs with this data.


                                    Its really easy having a menu for this, but a palette would maby be even cooler. I have no idea where to start, but I think you do it in flash?

                                    • 15. Re: Refresh window
                                      Harbs. Level 6

                                      I meant something like this:


                                      var script = "eval('app.doScript(File(" + script_path + "))')";


                                      If that doesn't work, you can use APID which allows you to run a script in a specific scripting engine like this:




                                      I also think you should try adding the menu item to one of the regular menus. I have a feeling it'll work there.


                                      Yes you can do a panel in Flash. Check out the CS SDK forum here: http://forums.adobe.com/community/creativesuites/cs_sdk



                                      • 16. Re: Refresh window
                                        Pontus Uggla Level 1

                                        I never really found a solution, I just had it right to a logfile that I read in my text editor.


                                        Now when I try it in CS4, it has stopped working there as well..!


                                        I think I did an update last week that probably did this. Do you know if there is a change log somewhere?


                                        I was thinking that if I could read the log, maby I can make InDesign do the same?

                                        • 17. Re: Refresh window
                                          Harbs. Level 6

                                          Did you ever try running this in one of the main menus? The problem that I ran into was limited to "non-standard" menus.



                                          • 18. Re: Refresh window
                                            Pontus Uggla Level 1

                                            I did, same result. But I did the change a bit too quick and accedently deleted the Object menu, I had to reinstall InDesign, could find another solution...


                                            I could try it again with other menus, but i was hoping for a better sollution, since the menu is so big.

                                            • 19. Re: Refresh window
                                              Pontus Uggla Level 1

                                              I still cant get it working...


                                              I´m thinking of learning how to do a plugin, and it seems that I can run scripts from a plugin, so i dont have to do it all over.


                                              I´m on a mac, so i downloaded the SDK and compiled some examples using Xcode, but thats about it.


                                              Do you guys have any tips on how to move on? I know php and javascript quite well, but this is a new world for me.