11 Replies Latest reply on Aug 12, 2009 11:33 AM by mrvodka

    Set script to run automatically every Saturday and Sunday

    TylerWray

      Title

      Set script to run automatically every Saturday and Sunday

      Post

      I'm using FM Pro, and am trying to set a script to run automatically every Saturday and Sunday when we're not in the office. Can anyone recommend a good strategy for accomplishing this?

       

      The script basically performs a find in order to send e-mails to several different found sets. Thanks!!

        • 1. Re: Set script to run automatically every Saturday and Sunday
          mrvodka
             You can use a scheduler program to fire a filemaker file which ha a script that fire upon opening. This script will run the email script in the other file.
          • 2. Re: Set script to run automatically every Saturday and Sunday
            philmodjunk
              

            Are you just using FMP or do you have Filemaker Server? With server and and SMTP email server, you might be able to set this up through a server scheduled script.

             

            Without server, I'd look into using Install On Timer Script. You could set this timer for once every 24 hours and then write the script this step controls to execute only if the day of the week was Saturday or Sunday.

            • 3. Re: Set script to run automatically every Saturday and Sunday
              TylerWray
                

              Thanks for your quick response! Nope, no server, unfortunately. 

               

              But, the Install OnTimer Script sounds like it would work. Would you mind providing some details about what such a script would look like? Thanks again, in advance! 

              • 4. Re: Set script to run automatically every Saturday and Sunday
                philmodjunk
                  

                Mr. Vodka's method will work also though the specific details will vary depending on whether it's a Mac or Windows machine.

                 

                Using Install OnTimer Script requires two scripts. The first contains the OnTimer step and the second sends out your emails.

                 

                Make your first step:

                 

                If [ Get ( UserCount ) = 1 ]

                 

                Then add: 

                Install OnTimer Script [“<script name>”; Interval: 86400]

                 

                End If

                 

                checking the number of users ensures that if a client has the file open at the same time as your host over the weekend, the script will only be launched from the host computer.

                 

                 

                Put the name of your send email script in place of <script name> and specify an interval of 24 hours in seconds: 24 x 3600 = 86400 seconds.

                 

                For your second script:

                 

                At the start of your send email script, add an if step that checks for day of the week. Something like this:

                 

                If [ dayofweek ( get ( currentdate ) ) > 2 and dayofweek ( get ( currentdate ) ) < 7 ]

                 

                //put your send email scripts here

                 

                End If

                 

                Last step: Use file options to specify the Script containing Install OnTimer Script to run when the file is opened.

                • 5. Re: Set script to run automatically every Saturday and Sunday
                  comment_1
                     Note that an OnTimer script is installed in a specific window. If you close that window or quit the application, the scheduled script will NOT run.
                  • 6. Re: Set script to run automatically every Saturday and Sunday
                    RickWhitelaw
                      

                    If he wants the script to run only Saturday and Sunday, how would this (from PhilModJunk's script) work?

                     

                    "If [ dayofweek ( get ( currentdate ) ) > 2 and dayofweek ( get ( currentdate ) ) < 7 ]"

                     

                    Would this not evaluate to "Tuesday to Friday"? 

                     

                    I could be missing something of course . . . 

                    • 7. Re: Set script to run automatically every Saturday and Sunday
                      mrvodka
                        

                      I would not use On Install Timer here. The easiest way to do this is to create a scheduled task under Window scheduler or iCal to run on Sat and Sun. This scheduled task would basically open a local file.

                       

                      Basically here are the steps.

                       

                      1. Create a new file, lets call is emailer.fp7 You can delete out all tables and table occurrences if you want.

                      2. Create a script in that file that calls the external script ( which does the find and emailing ) to your main file. After calling the external script, you can have the last script step close the file and/or exit applciation.

                      3. Under File Options, there is an option to call a script when the file opens. Reference the new script.

                      4. Use Windows scheduler or iCal to open emailer.fp7 on Sat and Sun.

                       

                       

                      Also just thought I would mention this, but you could always reference your main file in emailer.fp7 directly by putting table occurrences of the Main file tables in the emailer.fp7 relationships graph. Then you could just do the find and email from the emailer.fp7 file itself. Then the opening script could just have those steps added. 

                      • 8. Re: Set script to run automatically every Saturday and Sunday
                        philmodjunk
                          

                        RickWhitelaw wrote:

                        If he wants the script to run only Saturday and Sunday, how would this (from PhilModJunk's script) work?

                         

                        "If [ dayofweek ( get ( currentdate ) ) > 2 and dayofweek ( get ( currentdate ) ) < 7 ]"

                         

                        Would this not evaluate to "Tuesday to Friday"? 

                         

                        I could be missing something of course . . . 


                         

                        Good catch on the typo, that should be "> 1" instead of "> 2".

                         

                        There's nothing wrong with using Mr Vodka's solution as I said in an earlier post. I use that method myself. It's a matter of whether you prefer to keep the entire solution in a single file that's completely the same for both platforms or use an External Scheduler to open a Filemaker "Robot" file to do this.


                        • 9. Re: Set script to run automatically every Saturday and Sunday
                          RickWhitelaw
                            

                          Hi Phil,

                           

                          Wouldn't your correction evaluate as Monday-Friday? Is there a "not" or two missing?  ">1" is later than Sunday. "<7" is earlier than Saturday.

                           

                          Rick. 

                          • 10. Re: Set script to run automatically every Saturday and Sunday
                            philmodjunk
                              

                            Geez, you are so correct.

                             

                            You need to either reverse the logic of the expression ( less than 2 OR greather than 6) or place the Send Email code inside an Else clause.

                             

                             

                            • 11. Re: Set script to run automatically every Saturday and Sunday
                              mrvodka
                                

                              Why not just make this simple and do:

                               

                              If [ DayOfWeek ( Get ( CurrentDate ) ) = 1 OR DayOfWeek ( Get ( CurrentDate ) ) =7 ]

                                Send Mail []

                              End If

                               

                               

                              or if you want to expand this to more than 2 days instead of using multiple ORs or ElseIfs.

                               

                              If [ PatternCount ( 167; DayOfWeek ( Get ( CurrentDate ) ) ]    // Where it sends the mail on Sun, Fri, Sat

                                Send Mail []

                              End If