14 Replies Latest reply on Aug 19, 2014 11:01 AM by Mike Duncan

    Shell Scripting - Using "osascript" cmd to open a database via a Server Schedule

    john__j

      Looking for help with respect to the proper syntax using an osascript command in a shell script to successfully open a local (unhosted) server database.

       

      The following osascript string is unsuccessful in opening a database when run in a shell script as scheduled by FMS:

      osascript -e 'tell application "FileMaker Pro"' -e 'open "/Library/FileMaker Server/Data/Databases/databasename.fmp12"' -e 'end tell'

        • 1. Re: Shell Scripting - Using "osascript" cmd to open a database via a Server Schedule
          taylorsharpe

          I know little about osacript other than it is a way to run Apple Script from the command line.  But I do know one of the most common problems when running script from FMS is that it is run by the User Account that is logged in to run FMS.  On the Mac it is usually "fmserver".  Make sure that fmserver has the permissions to run the this script. 

           

          My next question is why are you trying to open a file stored in what is normally the location that FileMaker Server stores live databases?  It appears to me you are trying to locally open a file that is being hosted by FileMaker Server.  How do you know that FileMaker server does not have that file open since that it is what it would normally do for files in that folder path. 

          • 2. Re: Shell Scripting - Using "osascript" cmd to open a database via a Server Schedule
            john__j

            The script is running with the proper permissions. In running it I get a "No User Interaction Allowed" error.

             

            I run a different script just before this one to unhost the database so I can open it up locally to auto-run a desired script. At the time this script is run the database is closed and unhosted by FMS.

             

            The problem here seems to be related to the error I described at the beginning of this reply.

            • 3. Re: Shell Scripting - Using "osascript" cmd to open a database via a Server Schedule
              taylorsharpe

              Can you run the script as user fmserver and a batch file outside of FileMaker?  I would do this just to prove it will work before adding FileMaker server scripting of system level batch files into the mix. 

               

              I do not think it is a best practice to open files locally (with FileMaker Pro application) in the live FileMaker Server folder even if they are closed.  If by accident the script runs while hosted by FileMaker server, be prepared for corruption and needing to go back to a backup.  I've even had Norton Antivirus scans corrupt a hosted file and all it was doing is scanning the file. 

               

              Would you mind asking why the script can't be run when hosted by the server?  What are you trying to do that you need to run locally instead of as a service?  There might be a better solution out there if you give us more information on what you are trying to accomplish. 

              • 4. Re: Shell Scripting - Using "osascript" cmd to open a database via a Server Schedule
                john__j

                The script is actually run under the FMS admin account credentials. The snipet I provided is actually the 3rd osascript command. I can omit this line and have the prior two perform correctly. So again, it has something to do with the "open" AppleScript command. For further clearity, the batch file I thinik you're referring to that I'm trying to run is actually a FileMaker script internal to the database solution that is triggered to run when the database is opened.

                 

                I don't mind answering you question as to why the script can't be run as hosted by FMS. As I insinuated earlier, the script I'm really trying to auto-run is a script internal to a database solution. And that script is recalculating global field values.

                • 5. Re: Shell Scripting - Using "osascript" cmd to open a database via a Server Schedule
                  taylorsharpe

                  If you are trying to reset global fields, you could do that in a startup script for each time a user logs on and thereby saving the hassles of unhosting a file, making changes, and rehosting it.  Would that take care of your needs?  If the globals come from long calcluations that would really slow down the opening script, you could run at night and store those values and just transfer them to globals with the opening script. 

                  • 6. Re: Shell Scripting - Using "osascript" cmd to open a database via a Server Schedule
                    john__j

                    Unfortunately, that would not be the best solution to our needs.

                    • 7. Re: Shell Scripting - Using "osascript" cmd to open a database via a Server Schedule
                      john__j

                      Anyone have experiance using the AppleScript open command in conjunction with osascript?

                      • 8. Re: Shell Scripting - Using "osascript" cmd to open a database via a Server Schedule
                        taylorsharpe

                        OK, sorry I couldn't help.  I suggest that you get with an Apple Consultant Network person that specializes in Server technology and would be trained in Apple Script.  AppleScript is not a FileMaker technology.  It is a different tool which is why there is probably not much response in this Forum.  You could Google Server ACNs or go by your closest Apple Store and talk to the Business-to-Business Rep. to ask for recommended ACN consultants in your area that know AppleScript. 

                        • 9. Re: Shell Scripting - Using "osascript" cmd to open a database via a Server Schedule
                          APIcoder

                          Something like this?

                           

                          #!/bin/bash

                           

                          /usr/bin/osascript <<-EOF

                           

                          do shell script "open -a '/Applications/FileMaker Pro 12 Advanced/FileMaker Pro Advanced.app'"

                          delay 5

                          tell application "System Events"

                          set processen to name of every application process

                          try

                          if processen contains "FileMaker Pro" then

                          do shell script "open '/path to db/db.fmp12'"

                          end if

                          end try

                          end tell

                           

                           

                          EOF

                           

                          I use another method, I invoke an AppleScript from a ShellScript

                           

                          #!/bin/sh

                          osascript /Scripts/run.scpt

                           

                          Inside Applescript the magic happens

                          • 10. Re: Shell Scripting - Using "osascript" cmd to open a database via a Server Schedule
                            john__j

                            Thank you for your 2-cents Taylor.

                             

                            I may seek your advice in contacting an Apple ACN.

                             

                            I realize AppleScript is not a FileMaker technology. But is is a supported technology. And seeing how many FileMaker users are out there and how Apple owns both I figured someone has to be out there with experience doing what I'm trying to do... It's amazing how little documentation is out there with regard to AppleScripting and FileMaker.

                            • 11. Re: Shell Scripting - Using "osascript" cmd to open a database via a Server Schedule
                              APIcoder

                              Did you test the code?

                               

                              It works for me, the database in the folder /Library/FileMaker Server/Data/Databases/....fmp12 is opened in FileMaker Pro

                               

                              I have not tested it from Fmp schedule System level Script,

                               

                               

                               

                              I tried to run system level scripts, but have some problems with privileges.

                               

                              I have changed /etc/sudoers, like Filemaker documented, but that screwed up Filemaker Server updates ( and still the scripts will not run )

                               

                              maybe something I've missed in the documentation?

                              • 12. Re: Shell Scripting - Using "osascript" cmd to open a database via a Server Schedule
                                john__j

                                I've been testing your second method, the one that invokes the AppleScript from a ShellScript. I'm having a hangup running it that way. Basically the AS script step "activate" does not seem to work properly. When running osascript /Scripts/run.scpt (where run.scpt is substituted with the specific name of my script) from the command line, the application focus is never shifted from Terminal to FileMaker. I need FileMaker to be the active application so I can clear the necessary pop up dialog messages and continue on with my scripting sequence. So to successfully make it run I have to click on the FileMaker doc icon. Once I do, everything works fine.

                                 

                                I have not gone the route of changing the sudoers file myself. I've been trying to make my attempts work natively.

                                 

                                As for your first suggestion, I have not tried that yet...

                                • 13. Re: Shell Scripting - Using "osascript" cmd to open a database via a Server Schedule
                                  APIcoder

                                  I use the second methode for years from a Cron and no problem,

                                  I use some tricks to get by the Filemaker dialog.

                                   

                                  ( Shell Script )

                                  1)     Open Filemaker Pro app

                                  2)     Open a "startup.fmp12" Filemaker database  ( only access local ) with account enabled in File options

                                          and in Security the accounts of the other databases enabled

                                  3)     The "startup.fmp12" (Script step) database opens the databases in /Library/FileMaker Server/Data/Databases/ FMP

                                   

                                  Add this lines:  (Script step)

                                   

                                  delay 10

                                  ignoring application responses

                                       tell application "FileMaker Pro Advanced"

                                            do script "your script name" -- script opens the database in /Library/FileMaker Server/Data/Databases/

                                       end tell

                                  end ignoring

                                   

                                   

                                  You have to use the first methode,

                                  I think you will come across some privileges issues (running a seconds script from Filemaker System level Script).

                                   

                                  Are you sure that schedule start your System level Script?

                                  You get no notification from Filemaker Server "Aborted by User"

                                   

                                  If I try to run a System level Script, I get "Aborted by User"

                                  Privileges of the shell file are set as fmServer and fmsadmin,  Chmod 755

                                  Maybe you can give me some directions

                                   

                                  I have followed Filemaker documentation, which indicates to adjust the file sudoers, with no luck

                                  Now I think, maybe the hostname I used was wrong.

                                  • 14. Re: Shell Scripting - Using "osascript" cmd to open a database via a Server Schedule
                                    Mike Duncan

                                    If all you need the applescript to do is to open a file, why not bypass the applescript portion of it? You already have a shell script that does some other stuff, as long as filemaker pro advanced is the default app to open .fmp12 files, you can just

                                     

                                    open my_file.fmp12

                                     

                                    If there are other steps to run, you can create a dedicated filemaker file that does all the necessary script steps in filemaker and then close itself, set to run on open, and have your shell script open that one instead.