8 Replies Latest reply on Dec 1, 2011 12:46 PM by thosliot

    Trigger for a window activation


      Does anyone know if there is a trick to check a window becomes activated by a script trigger?


      I know that I can check the frontmost window using the WIndowNames function, but I need a trigger event to call an on timer routine both for the deactvated of the windw and activation of another.


      Enter and exit layout doesn't seem to do the trick.


      Ron Smith, MD


        • 1. Re: Trigger for a window activation

          HI Ron,


          It may help if you could be a bit more clear on what you want to happen and what the start and finish of the sequence is.


          So that stated,  you can use the WindowName() function to get all of the names of the windows the file has open.  Put the information into a variable and see if a window with specific name is open.


          You can also do things like add a script trigger to a specific layout so that OnLayoutEnter a On timer trigger is started.  The timer script could close the window and or open a new window to meet your requirements.


          Hope this is helpful.

          • 2. Re: Trigger for a window activation

            Here is the situation. PapCutPro is a very high end compete patient management solution with very sophisticated electronic records in which I have successfully created blinking colored field backgrounds for certain important fields.


            In addition to the main patient management window, I have created a Lab Console window complete lab results entry. It also sports 4 timers for the various lab tests we do which require that (strep, flu, mono, HCG, Urine Culture, and RSV for example). The window updates and displays blinking backgrounds for certain of the timer fields using an On Timer script routine that simply Refreshes cached external data. The color of the background indicators quickly tell the nursing staff whether a timed lab test is still in progress (yellow background) or if the lab test timer is done (colored background matching the color in the column of the timer chart) and the test needs to be read and entered. This is done with a conditional for the fields.


            The main patient management window is a list view of the current patients in the clinic and also sports related fields to only one of the timer fields for each of the four timers, and in a very small square at the end of each line. These also have blinking backgrounds that work through an On Timer routine that Refreshes cached external data.


            The main patient window however is also used to management most of the other medical records and other practice functions.


            I have the On Timer functions for the main window being turned off when the layout is exited in the main window and turned back on when the patient list is again displayed.


            However when the main patient window is displayed, if the Lab Console window is up and displayed behind it, I would like to turn off the On Timer routine for it.


            Where I can easily trap for the change of layout in the main patient management window and start and stop the On Timer routine using layout triggers, I can not trap for a change in the frontmost window when going to and from the patient management window and the Lab Console window.


            There is no trigger for that specific event.


            My question is, has anyone discovered a workaround the lack of a trigger for window activation. I know that the WindowNames function returns the window names in order and with the frontmost window first in the list and that would be essential for a trigger script.


            The blinking field backgrounds are very important for the nursing staff since I have two nurse practitioners colleagues and we see a full Pediatric load. And it is really cool too!


            Does that help?



            • 3. Re: Trigger for a window activation

              HI Ron


              Possibly a fairly easy method would be to use a global variable.  Have the variabel set to a specific value when the Lab Console window opens and have it change to a different value when the window closes.  If you have multiple Lab console windows open,  use a numeric value.  0 = no window open.  1 and above = number of Lab console windows open.  On Open add 1 on close subtract 1 from the variable.


              When the Main console window opens and goes to set the timers have the script check the status of the variable and set or not set the timers as required.


              I think this should simplify your window management and make it easy to determine if the window in question is open. 


              Hope this helps.

              Bruce Herbach

              • 4. Re: Trigger for a window activation

                But the problem is not when windows open or close. These two windows are already open. I need to respond to one being activated and brought to the front you see. There just is not trigger that traps for that event that I can find.



                • 5. Re: Trigger for a window activation



                  Try adding this to your on timer script in the form of an if statement.  If the value is 1(true) then the window is in front.  If not some other window is in front.  


                  GetValue ( WindowNames ( Get ( FileName ) );1 ) = Get ( WindowName )


                  This should let your scripts determine if their window is in front and perform the active functions or skip them if some other window is in front.


                  By the way if you leave out the Get(fileName) argument to WindowNames it will show all open windows,  the active window should be the first one in the list. 

                  I think this should let you add the logic you are looking for to your existing scripts.


                  Bruce Herbach

                  • 6. Re: Trigger for a window activation

                    Yes, that is what I thought too for turning the On Timer off, but how do you trigger it to turn on? The whole idea of turning the On Timer on and off instead of simply using if/then logic in a continually cycling On Timer script was to stop the CPU cycles that can affect the processes in other windows.



                    • 7. Re: Trigger for a window activation



                      Once you start an ontimer script it should run every X seconds until it is killed or you close the window.  So use a starter script when the layout is opened that runs the Install On Timer Script step.  Then add the window logic above at the beginning of the script.  If it is false,  just exit the script.  It will check again next time it runs.  Below is some of the help information from FileMaker



                      This step repeats until the window in which it is running closes or its options change. You can also halt the step by specifying another Install OnTimer Script script step for the window with no script specified.

                      The default interval is blank; you must specify a script and an interval. Specifying blank for interval cancels any OnTimer scripts that are running for the selected window.


                      The following example runs the script MyScript every 10 minutes.

                      Install OnTimer Script [“MyScript”; Interval: 600]


                      The ontimer process should use a fairly small amount of cpu cycles.  I wouldn't worry about it the timer itself slowing the system down.  That stated... what is the time between runs?



                      • 8. Re: Trigger for a window activation



                        I suspect you need to have a single OnTimer triggered script which refreshes all the appropriate windows - in order do do this you will need to use one or more globals to keep track of layouts and/or windows.


                        I haven't worked out the details of this but I'd guess the bare bones would be:


                        for all relevant layouts, trigger a script OnLayoutEnter and OnLayoutExit which tests the global(s) and acts accordingly, the options being:

                             1      OnLayoutEnter if global is empty, implying no relevant layout is being displayed: populate the global(s) to reflect that this layout is now being displayed and install the OnTimer triggered script

                             2     otherwise simply update the globals to reflect the new situation re the relevant layouts being displayed, and …

                             3     … (for OnLayoutExit only) if this results in no relevant layout being displayed, unInstall the OnTimer triggered script


                        the OnTimer triggered script uses the method already described to determine the current front window and uses the global(s) to determine which layouts/windows it needs to refresh


                        In this way you should be able to have the onTimer triggered script installed only when required - I think :-]