2 Replies Latest reply on Jul 10, 2011 7:16 PM by johnhinsley

    How to wait for a file to close

    johnhinsley

      Title

      How to wait for a file to close

      Post

      Probably very simple question, please don't shoot the newbie.

      I want my script to do this:

      <some stuff>

      Open File "something"

      <some more stuff>

      ..but I don't want the "more stuff" to happen until File "something" has done its thing and closed. Seems like a simple request? It would be easy in a shell script, for instance, where you can opt whether or not to wait for a called program to finish until you resume.

      I've tried Pause/Resume before the <some more stuff>, but then I need to Resume before "something" gets to do its stuff.

      RSVP!

        • 1. Re: How to wait for a file to close
          philmodjunk

          Pause/Resume can be set to pause the script for a specific number of seconds so you don't have to have a user resume the script for it to continue.

          Assuming that this file is a FileMaker file, you can use the windowNames function to check to see if the file is opened by checking the list this function returns for the file's window name. This will only work if you do not hopen the file with the "hidden" option selected, however.

          Open File "Something"
          Loop
             Pause/Resume [5 seconds]
             Exit Loop If [ IsEmpty ( FilterValues ( WindowNames ; "Something" ) ) ]
          End Loop

           

          • 2. Re: How to wait for a file to close
            johnhinsley

            Hi, thanks for your reply. I can't get it to work though. What happens is the layout for "Something" flashes up briefly but then I see the layout for the original file once more; and then I can that the calling script has control again. I can see the cursor change every five seconds. There seems to be no way out of the loop, moreover - I had to kill the process with Windows Task Manager.

            I repeated the exercise using DatabaseNames instead of WindowNames, same result.

            Again, am I missing something obvious? Like - is there any way of controlling which file is the "active" one? Does FileMaker always favour the file which opened first or something? 

            -----------------------------------------------------------------------

            Hi again - cracked it. You have to put the every-5-seconds test in an OnTimer Script rather than a Pause/Resume. That way it DOES give up control to the Opened file and allows it to do its thing. When the test shows that the file has closed, then the OnTimer script does the cleanup actions I want it to and then cancels itself.

            So now I have two scripts:

            script 1:

            <some stuff>

            Open File "something"

            Install OnTimer Script ["script 2"; Interval: 5]

             

            script 2:

            If [IsEmpty (FilterValues(DatabaseNames; "something"))]

             <some more stuff>

             Install OnTimer Script[]

            End If

             

            - and this works. Not altogether happy about this waste of the world's computer resources to test something every 5 seconds when there should be a synchronous way to do it, but...