9 Replies Latest reply on Nov 13, 2014 5:20 PM by Vincent_L

    Options for "Perform Script By Name" Functionality?

    steve_ssh

      Hello,

       

      Lately, when I've needed to invoke a FMP script where the target script is determined at runtime, I have been using a webviewer and the FMP URL protocol to trigger the script.

       

      Though I don't have frequent use for this, it has been a nice technique to have in my toolbox.

       

      This has worked fine for limited purposes so far, but it does require that I have a webviewer available somewhere on some layout.

       

      This morning I was playing with the idea of using AppleScript (using do shell script) to trigger the FMP URL and pass any desired parameter. This seems a little cleaner to me, though it does severely limit the platform possibilities.

       

       

      Questions:

       

      Has anyone else been using this particular technique, and if so, do you have any comments to share about it, e.g. possible pitfalls, successful use cases?

       

       

      Sample File:

       

      I'll attach the demo file that I've been working with to this post.

       

      I'd be curious to know if it seems possible that this technique could be generalized to the Windows platform.

       

       

      Comments:

       

      • The technique does not work (or so it seems) if used while the FMP script stack is in the middle of processing script steps. It seems to work fine if there are no other script steps remaining to be processed at the time that it is invoked.

       

      • For iOS purposes, the WebViewer technique may still be my best resource.

       

       

       

      Thank you and kind regards,

       

      -steve

        • 1. Re: Options for "Perform Script By Name" Functionality?
          wimdecorte

          steve_ssh wrote:

           

          This morning I was playing with the idea of using AppleScript (using do shell script) to trigger the FMP URL and pass any desired parameter.  This seems a little cleaner to me, though it does severely limit the platform possibilities.

           

           

          Questions:

           

          Has anyone else been using this particular technique, and if so, do you have any comments to share about it, e.g. possible pitfalls, successful use cases?

           

           

          I've demoed a similar approach through ActiveX on Windows about a decade ago, There used to be a demo file available for this, called something like "run script by redirection".

           

          The issues mainly tend to be timing: whether or not you need or want to wait for the script to complete.  There is a definite order in which FM puts scripts in the stacking order and scripts called by AppleScript and ActiveX tend to go fairly low in that order.

          In that sense you need to carefully craft the hand-off between internal scripts and the scripts called from the outside.

          • 2. Re: Options for "Perform Script By Name" Functionality?
            ryantittle

            Steve,

             

            I haven't checked out your new method via AppleScript ( I'm on Windows ) but I'm a bit confused by your comment of needing a webviewer on the layout. I've never had any trouble calling the fmp protocol via the Open URL script step. I threw together a quick example file, but alas, I can't seem to figure out how to upload it with my comment. It should be easy enough to test yourself, or I could upload the one I have if you could point me in the right direction.

             

            Nevermind, I found it.

             

             

            Ryan

            • 3. Re: Options for "Perform Script By Name" Functionality?
              steve_ssh

              Hi Ryan,

               

              I had completely overlooked the possibility of using Open URL script step to do this -- That seems like it would be much better for this sort of task.

               

              Thank you for mentioning it.  I'm going to check it out.

               

              Many thanks and very best,

               

              -steve

               

              Addendum: Thanks for the sample file!

               

              Addendum 2:  If I could like your reply several times, I would.  What you did is much better, and doesn't introduce any platform issues.  Thank you again Ryan!

              • 4. Re: Options for "Perform Script By Name" Functionality?
                steve_ssh

                Thank you for the information Wim.  I appreciate it.  I have indeed been finding that AppleScript does seem to fall low in the stacking order.  I don't see this as wrong -- just something which needs to be understood and dealt with, as you mentioned.

                 

                Thank you,

                 

                -steve

                • 5. Re: Options for "Perform Script By Name" Functionality?
                  monkeybreadsoftware

                  If you use MBS Plugin, you can use the functions

                   

                  FM.RunScript, run a script now:

                  http://www.mbsplugins.eu/FMRunScript.shtml

                   

                  FM.RunScriptLater, run a script in a few seconds or minutes:

                  http://www.mbsplugins.eu/FMRunScriptLater.shtml

                   

                  FM.RunScriptIdle, run a script when using is idle for some time:

                  http://www.mbsplugins.eu/FMRunScriptIdle.shtml

                   

                  For all you can pass filename, scriptname and parameter as text and you can calculate them.

                  • 6. Re: Options for "Perform Script By Name" Functionality?
                    ch0c0halic

                    I use the Open URL method very successfully. I have a field with a sequence of script names and a master dispatch script that traverses the list and uses Open URL to run whatever scripts I want in whatever order I need them to run.

                     

                    My URL calculation looks like this.

                    "fmp://" & Get ( HostName ) & "/" & Get ( FileName ) & "?script=" & $script_name & "&param=" & $script_param

                     

                    Primary concern is of course context. Turns out because the Open URL is calling the local FMP client it works within the current clients context.

                    • 7. Re: Options for "Perform Script By Name" Functionality?
                      steve_ssh

                      Thank you ch0c0halic.

                       

                      This is very cool, and I look forward to swapping this into a project where I have gone down a needlessly complex path to accomplish the same result.

                       

                      Very best,

                       

                      -steve

                      • 8. Re: Options for "Perform Script By Name" Functionality?
                        steve_ssh

                        Thank you Christian.

                         

                        BaseElements and ScriptMaster have some similar functionality which I have used in the past.

                         

                        The plugins work really great.  One advantage of the plug-in approach is that it allows for triggering the script from the context of the calculation engine, which is a very powerful ability.

                         

                        Thanks for adding to the conversation.

                         

                        Very best,

                         

                        -steve

                        • 9. Re: Options for "Perform Script By Name" Functionality?
                          Vincent_L

                          Perform script by name, or by ID, is sorely missing. We could do a lot of things with it.

                           

                          The open url doesn'tw work for me, for 3 reasons :

                          - Not server side compatible

                          - When I tested on the client, there was some flashing, or it openend a new window, I don't remember

                          - Parameters must be encoded, they're much more limited in size than rela parameters

                           

                          So, I resorted to create a script to which I pass script_id, and filnemane, and in which I've lots of else if that branches to the correct script

                           

                          So please plese plese FMI, create a real Perform script by Name / ID (same interface as layout with also file specification. This will open tremendous possibilities.