10 Replies Latest reply on Jul 9, 2015 10:51 AM by Atcha

    (Double) click trigger

    Atcha

      Title

      (Double) click trigger

      Post

      I would like to run a script when a user clicks on a container object in a form, but this option is not listed among the options, and the FM Knowledge Base "Understanding and using Script Triggers" does not mention it. I now use "OnObjectKeystroke" to trigger the script, but that is silly. I must be overlooking something, so how does one link a script to a (double) mouse click on an object?

        • 1. Re: (Double) click trigger
          philmodjunk

          This is usually not a very workable option in FileMaker. There are ways to do it, but the scripts are a bit convoluted as you have to use a button setup and the script responds to both the first and second click. You have to then write the script so that it notes the first cick but does not do anything until the second click. Either that or you look for a plug in.

          It's much simpler to set up a script that checks for a modifier key such as shift, control, command, option, Alt, that's down and uses the presence or absence of that added keydown to determine what action to take.

          Note that without any scripting at all, you can set a container field to open the inserted file in its default application with a double click if you set up the storage, layout and insertion methods/options just so. This does not use any script at all.

          • 2. Re: (Double) click trigger
            Atcha

            I am a novice in FM so I have to read your answer really carefully to see what you mean and I now think I may have wrong-footed you with my question. I am not particularly concerned with a double click (I am after all working on a Mac), a simple click will do.

             

            How would I ago about, as you put it, setting "up the storage, layout and insertion methods/options just so". I had a good look at the options listed by the Inspector for this object but saw nothing obvious.

            • 3. Re: (Double) click trigger
              philmodjunk

              For a single click, the OnObjectEnter can be used to run a script and you can select a button while in layout mode and use button setup from the Format menu to set up the field as a button. This removes direct access to the field on the current layout, so you have to figure out if that's a problem for your layout design or not.

              Opening files from a container field by double clicking used to be a kind of "standard practice" in FileMaker. Then the powers that be added a lot of design options to container fields and most of the added features prevent the double click feature from working.

              The field cannot be set up with external storage
              The field cannot be optimized for interactive content on the layout where you want to use the double click.
              The file must be inserted into the container field with "insert File" and the "store a reference" option must have been selected.

              Then the double click method will work

              Alternatively, you can use Export Field Contents in a script in order to open any file from any container field. This exports and then opens a copy of the file so the result is not quite the same as the original double click method.

              • 4. Re: (Double) click trigger
                Atcha

                I tried the OnObjectEnter and that works fine (big thank you). The only disadvantage is that if you remain on the object and then click on it again the script will not execute (but this is unusual so matters little).

                I am not sure I understand the "standard practice" of clicking. I think this is exactly how I have my container set up: no external storage and references only and not optimized for interactive content (it is an image container), yet nothing happens when I click on the container (I am using FMP 14).

                • 5. Re: (Double) click trigger
                  philmodjunk

                  With OnObjectEnter, you can write the script to exit the field so that clicking it again trips the trigger again. Go to next field, go to field, go to object, commit records are all steps that can change the focus to another layout object or remove the focus and thus clicking the field a second time trips the trigger again.

                  The second option requires a double click. It's functionally as though you found the image file via your OS and double clicked it to open it. And the one thing that you did not mention was whether or not your file was inserted with the "store a reference" option enabled and when using Insert File as the insert method.

                  • 6. Re: (Double) click trigger
                    Atcha

                    Oops, sorry by "references only" I meant only the reference is stored not the image, i.e. with "Store only a reference to the file" enabled. As to using the Insert File method, yes that is the only one I have used so far (no dragging or dropping, even though I read on this forum that on a Mac even with dragging and dropping the file is never embedded). Still, I can double click until I am blue in the face but nothing happens. I'll set up a brand new container on a test form to see if it works there.

                    • 7. Re: (Double) click trigger
                      philmodjunk

                      But since this is a container for images, did you use insert picture or insert file to insert the file into the container? If you use Insert Picture, it doesn't work. If you use Insert File, it does.

                      even though I read on this forum that on a Mac even with dragging and dropping the file is never embedded)

                      This is not the case. Drag and Drop ALWAYS embeds the file. If however, external storage is specified, FileMaker (on both platforms) will then export the file to the external storage location and update the container to contain a reference to that file's new location.

                      • 8. Re: (Double) click trigger
                        Atcha

                        Aaah ..., I did use Insert Picture, but if I use Insert File, I don't get to see the image UNLESS I double click on it? If that is right it doesn't much help. Why make the distinction .... (exasperation) at all?

                        My last messages prove again that a little knowledge does not go a long way, quite the contrary in fact!

                        • 9. Re: (Double) click trigger
                          philmodjunk

                          That's a good question. If you were to look at the text data actually stored in the container when you use either insert picture or insert file to insert a file reference, you'll find that the data is not the same. While both insert a file reference, insert picture also inserts some additional data. My only logical guess is that the FileMaker Programmers never bothered to write some code that would extract the needed file path both from both inserted pictures and inserted files even though the code needed to do so is very trivial.

                          In theory, you could use a script that does an Insert File to insert a second reference to your inserted picture into a different container field and then you could have one container field to show the image (or at least it's thumbnail) and a different one to double click. But that seems pretty silly just to get a way to open the file. Export Field Contents via a script seems a simpler option.

                          To learn more about container fields, File Paths and the scripts that use them, see: Exploring the use of a $Path Variable in Scripts

                          • 10. Re: (Double) click trigger
                            Atcha

                            Trivial indeed, at least I can work around it. Thanks for the reference to the other post. I can sure do with such instructions and have downloaded the file. Should be interesting!