5 Replies Latest reply on Apr 14, 2011 7:50 AM by mgores

    Send Event script to open a pdf file

    MaxEh

      Title

      Send Event script to open a pdf file

      Post

      I am trying to open a pdf file using the Send Event script step in FMP 11A. I thought I could generate a calculated file path and name for each record in the database for Send Event to use however I get "There was an error opening this document. This file cannot be found."  The application opens just not the file

      I am using a calculated field ( cal_FilePath (tried both stored and unstored as Text)) to generate a relative file path "file:pdfs/" & cal_Method Number & ".pdf" which shows up as file:pdfs/2539.pdf  which from all the guides and online discussion I've looked at seems to be correct for a relative file path.

      In Send Event I have selected "Specify Application" and Adobe Reader.app, as a default (since I'm hoping to do this in a mixed OSX/Win environment).  I have used Send the: open document : event with 'Calculation' : cal_FilePath and checked Bring Target Application to foreground.   This does not want to work.  I have tried all combinations of Options available in the dialogue but no luck.

      I have pasted the calculated result from cal_FilePAth in the  Send the: open document : event with 'Document' dialog.  This works but I have a thousand different files and that seems tedious.

      I have also tried the OpenURL script but that did not work for me either.   The relative file path is important as I would like to provide clients with a runtime solution.

      What am I missing or doing wrong? Send Event appears to be the right way to do this.

        • 1. Re: Send Event script to open a pdf file
          philmodjunk

          The file paths need to include the full path. A relative path, as far as I know, won't work with these two steps (send event and open url). You'd need to compute the full path starting from the drive letter (windows) or volume name ( macs).

          You could insert the file into a container field with "store by reference" to enable a relative path to the document. You can open said document by double clicking the container field or by using Enter Field or Export Field Contents in a script. You can also use a web viewer to view the PDF, but you still have to compute the full path to the document in the Viewer's URL expression.

          There's also a third party add on, called supercontainer that you can investigate.

          • 2. Re: Send Event script to open a pdf file
            mgores
            Martin, I have done something similar.  In order to make it work I set up the text field with the calculated filepath as you did.  One of the keys was to ensure that the file is stored to a folder that everyone can access and that it is stored as a reference.  From Jim's computer the path may be desktop/file.pdf, but when John goes to open desktop/file.pdf he gets a file not found error.  To do this I made a script that is triggered on modifying the container that takes the file and exports it to a specific location on the server, then replaces the contents with that exported version of the file (as reference).  That way the user does not have to select the save as reference and the file will be on the server for all users to find. Then to make it cross-platform you will need to make the open file script determine the platform type and substitute filemac: or filewin" as appropriate.  I did this by defining a filepath variable and setting it to a calculated result based on the platform and the filepath field for the container.
            • 3. Re: Send Event script to open a pdf file
              philmodjunk

              A useful function for computing the full path equivalent to a relative file path (path to a file in the same directory as the database file) is Get (filepath).

              • 4. Re: Send Event script to open a pdf file
                MaxEh

                Mark and Phil,

                Thanks for the input.  I have done some quick testing but Mark I'm not sure I am fully grasping your concept.  I have a folder with hundreds of pdf files (oddly enough named pdfs).  It will be located with the main file since it will be used primarily as a runtime version.  So if I understand correctly I will have to import the file into the container field which because it has been modified will then trigger a script that will export the file; again in my case to the pdf folder, leaving behind the file as a reference.  Another calculated script defining the file's location is then used by Send Event to retrieve (from folder pdf) the file and open using the assigned application.  The file path based needs to be the complete file path as well as Mac/Win for cross platform functionality.  It appears to me that I still need to import the files one by one to create the reference.  Looks like I'll need to design a script to automate that part a bit.

                Well I'm going to puzzle over this for awhile, other things have landed on my plate that I need to address.  I currently have other ways of accessing the same information and this was a " ...wouldn't it be neat if I could ...." marry the two mostly for fun and learning challenge.  The FMP community is amazing and I love the program - now if I could only learn how to really use it!

                • 5. Re: Send Event script to open a pdf file
                  mgores

                  Martin,

                  In my application, I needed a place for the users to place files received with requests for quotes.  I wanted to be able to place those files in containers related to the quote record so that anyone reviewing the quote at a later date would be able to view those associated files.  I set up the container field to run the "filestore" script on modification.  That script takes the file that is inserted in the container field and saves it to a folder on the server (in my case the folder is determined by a variable since there are folders for each customer).  I also modify the file name by adding the quoteID number to the front of the filename, since sometimes we get files with the same name.  The script then replaces the originally inserted file with the modified version from the server with the "as reference" option.  This ensures that the file is inserted as reference whether the userr selects that option or not and places the file in a location that everyone will have access to.

                  Then there is a text field that is a calculated value of that container field.  When you look at that text field is something like this

                  file:652-SEM RFQ.doc
                  filemac:/Server/quotes/customername/652-SEM RFQ.doc

                  I then set up a button to open that file using a script where I set a variable to a calculated value that uses the file path from that field, modified for the user's platform.

                  It would take a little wrangling modifying a DB that already has the files in the container fields, but I'm sure you could write a little temporary loop script that goes through each record and moves the files.  From then on any additional records/files with be done as they are inserted.