1 2 Previous Next 16 Replies Latest reply on Mar 13, 2017 10:55 AM by BruceRobertson

    AppleScripts and Field Contents

    hasenmaus

      I would like to extract the value of field in Filemaker Pro 11 and concatenate the field value as text to a defined string constant. The concatenated string would then be used to open a file stored locally on my computer.

       

      For example if the value contained in a text field called InvoiceNumber was "79121". I would like to extract the value "79121" from the field and concatenate it to two other fields to form the string "/Users/hasenmaus/Desktop/VetInvoices/Inv_" & FieldValue(79121)  & ".pdf". That concatenated string would be the path to have say Adobe Reader open the file and have its contents displayed in Adobe Reader. Can this be done in FMP v11?

       

       

      AppleScript attached to a Filemaker Pro button and fires when pressed by the user

       

      tell application "Adobe Reader"

         

          activate

         

          try

             

              set the chosenDocumentFile to ¬

                  "/Users/hasenmaus/Desktop/VetInvoices/Inv_79121.pdf"

             

              open the chosenDocumentFile

             

          on error errorMessage number errorNumber

             

              if errorNumber is not -128 then

                  display alert errorNumber message errorMessage

              end if

             

          end try

         

      end tell

        • 1. Re: AppleScripts and Field Contents
          fclark

          Try substituting "/" with ":" in your path

          • 2. Re: AppleScripts and Field Contents
            fclark

            i believe your path may need to start :Macintosh  HD:users:

            • 3. Re: AppleScripts and Field Contents
              hasenmaus

              The issue is not with the path. The file opens using either the "/" or ":" to denote the pathway. My issue is to extract a text value from an existing field and concatenate the value with another string value.

               

              For example:

               

              theValueInMyField = "This is the file needed"

               

              myString = ".xls"

               

              theChoseFileToOpen = theValueInMyField & myString = "This is the file needed.xls"

              • 4. Re: AppleScripts and Field Contents
                fclark

                create variable $filepath-> "file:/Macintosh HD/Users/yourName/Desktop/"&$file

                Use "Send Event" script step

                Send the - open document

                -document $filepath

                bring target application to foreground

                • 5. Re: AppleScripts and Field Contents
                  hasenmaus

                  Hi fclark

                   

                  Thanks for your suggestions. I have tried everything and cannot retrieve the value contained in a field of the active record and assign that value to variable. This is a trivial task in most other computer languages. I can't believe this isn't possible in either FileMaker or AppleScript. For example in "C":  myNewVariable = *myOldVariable.

                   

                  Reading other posts in other FileMaker forums it seems this capability was removed around the introduction of FileMake v10.

                  • 6. Re: AppleScripts and Field Contents
                    BruceRobertson

                    "I can't believe this isn't possible.."

                    You are correct so far. It is not "not possible".

                    It is possible.

                    Not knowing how to boil water; and claiming that the water boiling feature was removed from your stove.

                    A curious and unsupported conclusion.

                    You may want to study the AppleScript dictionary more carefully.

                    • 7. Re: AppleScripts and Field Contents
                      philmodjunk

                      Why use AppleScript?

                       

                      This task can be done just using FileMaker.

                      • 8. Re: AppleScripts and Field Contents
                        hasenmaus

                        How can it be done using Filemaker. I don't want to store large scanned files within a container field in the database. I would like to create a link to the file and have the files native application, in this case Adobe, open up the file.

                        • 9. Re: AppleScripts and Field Contents
                          philmodjunk

                          If you insert a file into a container field "by reference" all you store in the container field is the file path to that file. That would seem to do exactly what you want here and you can use the path in that container field to open the file in your computer's default application. You would only need to double click the container field to get the file to open.

                           

                          Open URL should also work to open a file using the file's path--but I use windows and there could always be a glitch in how that works with Mac and FMP 11, but it should work.

                           

                          Send Event might also be used.

                          • 10. Re: AppleScripts and Field Contents
                            hasenmaus

                            I tried a container field in the past, but when I clicked on the contents of the container field the file does not open.

                            • 11. Re: AppleScripts and Field Contents
                              BruceRobertson

                              There are some repeating difficulties here with your imprecise statements.

                              You might try doing exactly what Phil said.

                               

                              When setting up the container, you have the option to set it as a reference.

                              IF you did what Phil said; it would work.

                               

                              insert file options.png

                               

                              However, you can also put the path to the file in a text field, and as he said, use Open URL.

                              Syntax shown here. Syntax is the same in FileMaker 11.

                               

                              FileMaker Pro 15 Help

                              • 12. Re: AppleScripts and Field Contents
                                hasenmaus

                                Phil and Bruce,

                                 

                                I used Phil's suggestion and the container field did exactly what I wanted, it launched the reference file in its native application. Sorry for all the confusion. The solution was a very simple fix to implement. Sometimes one just doesn't see the forest fore the trees.

                                BruceRobertson wrote:

                                 

                                There are some repeating difficulties here with your imprecise statements.

                                You might try doing exactly what Phil said.

                                 

                                When setting up the container, you have the option to set it as a reference.

                                IF you did what Phil said; it would work.

                                 

                                insert file options.png

                                 

                                However, you can also put the path to the file in a text field, and as he said, use Open URL.

                                Syntax shown here. Syntax is the same in FileMaker 11.

                                 

                                FileMaker Pro 15 Help

                                If you insert a file into a container field "by reference" all you store in the container field is the file path to that file. That would seem to do exactly what you want here and you can use the path in that container field to open the file in your computer's default application. You would only need to double click the container field to get the file to open.

                                • 13. Re: AppleScripts and Field Contents
                                  fclark

                                  glad you have an answer to your larger issue. 

                                  this code addresses your issue

                                  tell application "Preview"

                                   

                                    activate

                                   

                                    try

                                   

                                    set the chosenDocumentFile to ¬

                                    POSIX path of "/Users/yourname/Desktop/file.pdf"

                                   

                                    open the chosenDocumentFile

                                   

                                    on error errorMessage number errorNumber

                                   

                                    if errorNumber is not -128 then

                                    display alert errorNumber message errorMessage

                                    end if

                                   

                                    end try

                                   

                                  end tell

                                  • 14. Re: AppleScripts and Field Contents
                                    fclark

                                    that looked awful... It is the addition of the posix path that should get it to open.

                                     

                                    for passing a variable  - I do a calculated applescript. it requires a lot of escaping. see below.

                                     

                                    "tell application \"System Events\"¶

                                     

                                     

                                        try¶

                                           set filePath to POSIX path of \""&$filePath&"\"¶

                                        on error number errnum¶

                                           my errorHandler(errnum)¶

                                          return¶

                                        end try¶

                                       

                                        try¶

                                           set seeIfFileExists to alias filePath¶

                                        on error number errnum¶

                                            my errorHandler(errnum)¶

                                            return¶

                                        end try¶

                                     

                                    end tell¶

                                     

                                    on errorHandler(errnum)¶

                                    tell application \"Filemaker Pro\"¶

                                    activate¶

                                    set cell \"Main::GLOBAL_ERROR\" of current record of current layout to errnum¶

                                    return¶

                                    end tell¶

                                    end errorHandler"

                                     

                                    APPLESCRIPT your script that works using posix

                                     

                                    tell application "Preview"

                                     

                                      activate

                                     

                                      try

                                     

                                      set the chosenDocumentFile to ¬

                                      POSIX path of "/Users/yourname/Desktop/yourfile.pdf"

                                     

                                      open the chosenDocumentFile

                                     

                                      on error errorMessage number errorNumber

                                     

                                      if errorNumber is not -128 then

                                      display alert errorNumber message errorMessage

                                      end if

                                     

                                      end try

                                     

                                    end tell

                                    1 2 Previous Next