1 2 Previous Next 20 Replies Latest reply on May 24, 2012 9:50 AM by Sorbsbuster

    Problem with script



      Problem with script


      I am trying to get the following script to work. I am sure it is in my path but can not seem to find the right combination.

      The following works fine - do shell script "open ~/desktop/v001.tif"


      This dose not - do shell script "open ~/Macintosh HD 2/pictures/wells images/v001/v001_007.tif"

      I get the following message

      The files /Users/rogerwells/Macintosh, /HD, /2/pictures/wells, and /images/v001/v001_007.tif do not exist.


      I got this to work:

      do shell script "open /Macintosh\\ HD\\ 2/pictures/wells\\ images/v001/v001_007.tif"

      So it looks like the spaces caused my problem here.


      So the last question how do I get this into a variable?

      do shell script "open " $path

      where $path would = /Macintosh\\ HD\\ 2/pictures/wells\\ images/v001/v001_007.tif


      I want to do the following  do shell script Variable  

      Where the variable is the path to the picture

      Any help would be appreciated as this is the first shell script I have tried to do.




        • 1. Re: Problem with script

          What type of scripting is this? AppleScript or some other system script? "do shell script" isn't a FileMaker script--opening a file via a Filemaker script would use different methods.

          • 2. Re: Problem with script

            This is a applescript.


            Maybe I am using the wrong scripting. I am new to filemaker.


            What I am trying to accomplish is to click on a button and have that open the image in Apple Preview.


            What I have coded will open the image in prieview but so far I have had to hard code the path. I now want to do it within the script so that I can use the path statement used by filemaker.


            Could you offer a suggestion using a filemaker script? This is my first major project in filemaker pro 12.




            • 3. Re: Problem with script

              Hi Roger,  Try this:


              Your path should start at the root, so your hard drive name will be inside of the Volumes directory.


              set shCommand to "open /Volumes/Macintosh\\ HD/test.pdf"
              do shell script shCommand
              • 4. Re: Problem with script

                Why not store the file in a container field on the record (as  a 'reference only' link), then double-click the field and it will open the file?  In other words, use your FM database as a catalogue for the files?

                • 5. Re: Problem with script

                  I have the path stored in the database as 

                  imagemac:/Macintosh HD 2/pictures/wells images/v001/v001_007.tif

                  I use this file as the file path to show a small image.


                  How would I use this to open the file? My goal is to have what ever is shown in the container open up in the native application on the mac.

                  I am fimilar using the script but do not understand the reference link and how to store it in a container.

                  Kalwiter   --  That gives me what I need to use the shell command. I will just need to get the path into the right format.



                  • 6. Re: Problem with script

                    If you use 'insert file' and link to the image file by reference, then you will open the image if you double-click the field, or use the script step 'Go to field' and tick 'Select/Perform.

                    If you don't select 'Store a Reference only' then it doesn't work (and your file size will explode anyway), and it doesn't work if you use 'Insert Image' (not on Win XP and FM11, anyway.)

                    Otherw downside is you don't get an image preview.  (You could store it in two places, maybe - show the imagemac: one to see the preview, and tuck the filemac: (or file: one away out of sight...?)

                    • 7. Re: Problem with script

                      I think my question is a little bit confusing.


                      I have the file path in the database and the image shows in the container field. This works fine.

                      When I say that I want to open the image in Preview I am refering to program on the mac. I want to click on the image shown in the container field and have it open the same image in the Preview program on the mac.






                      • 8. Re: Problem with script


                        What version of FileMaker are you using?  It sounds like Sobsbuster is indicating that FM11 will launch a file by clicking on it.  I know that isn't the case for FM10.  I wrote an entire document library using container fields to store references and then used scripts to extract the path, and pass it to a OS script (Windows or Mac) to open the file.

                        I can give you some sample code tomorrow.


                        • 9. Re: Problem with script

                          Here is the key piece that extracts the path info into a variable:


                          Set Variable( $DocumentPath; 

                          $ThePath =  GetAsText(Get (ActiveFieldContents));
                          $Ptr =  Position ( Lower($ThePath); "_library/"; 1; 1) + 9;
                          $SubStringLength =  Length( $ThePath ) - $Ptr + 1
                          Middle ( $ThePath; $Ptr; $SubStringLength)
                          - - - - 
                          In the sample above, I am interested in knowing the variable part of the path to the file, from a known position in my file system.  I get the substring that follows ".../document_library/..." in the path.
                          Then, for each platform, I create the appropriate string ( e.g.:  "filewin://servername/share/document_library/" + $DocumentPath ) and then pass that to the OS shell.
                          If [ Abs(Get(SystemPlatform)) = 1 ]
                          // For Mac OS
                          Set Variable [ $DocPath; Value:Library::gDocumentLibraryPath & "/" & $DocumentPath ]
                          Perform AppleScript [ Calculated AppleScript: "do shell script \"open /Volumes" & $DocPath & "\"" ]

                          // for Windows
                          Set Variable [ $DocPath; Value:Library::gDocumentLibraryPath & "\\" & Substitute($DocumentPath; "/"; "\\") ]
                          If [ Get(SystemVersion) = 6.1 ]
                          #Windows 7 needs to use CMD START <path> instead of just calling the file directly
                          Set Variable [ $cmd; Value:"cmd /c start " & $DocPath ]
                          Set Variable [ $cmd; Value:$DocPath ]
                          End If
                          Send Event [ open document/application; $cmd ] [ Bring application to foreground ]

                          End If
                          Hope this helps.
                          • 10. Re: Problem with script

                            "...is indicating that FM11 will launch a file by clicking on it.  I know that isn't the case for FM10" - yes, that is what I'm saying.  And it works in FM10 as well as FM11.

                            - create a container field
                            - right-click (or mac equivalent) and Insert File...
                            - choose the image file and check 'Store a reference only'
                            - double-click the container file and the inage will open.

                            All steps can be scripted, including allowing the user to browse to 'any old file' and then re-importing it to the container friled with a system-specified filepath.

                            • 11. Re: Problem with script

                              Well I made the following test.


                              I created a new database with one container field.

                              I right clicked and followed sorbsbuster instructions and it works.

                              The big thing here is if you inseret a file by reference only it works if you insert  a picture by reference it will not work.

                              If you insert a file you only get a link to show in the container but if you insert a picture by reference you get a small view of the pricture.

                              Since my database needs to run on an iPad as well as a iMac I am going to have to test to see how to get the picture to show so it will be visable on the

                              iPad and iMac and to show in Preview when you click it on the iMac.


                              Thanks guy's it has been an interesting education to me and a great help as all of the ideals has given me some new ideals to try.

                              I like the code from klawiter and may end up using some of it.

                              I am using Filemaker Pro 12.

                              • 12. Re: Problem with script

                                You can have a container field on the layout with a reference to the 'image' the way you had it and use that as the display field so the user sees the image, and then have a tiny container field with the file inserted the way I suggested, which is actually the one that is 'double-clicked', but the user need never see it.

                                • 13. Re: Problem with script


                                  I understand how to make a script to do what you suggest.

                                  The one item I don't understand is how to hide the container so that the user will never see it but still be double clickabled?

                                  Can you give me some direction with this/



                                  • 14. Re: Problem with script


                                    How about using the field itself as the button.   That way, you can use the thumbnail in the container, then format that field as a button

                                    and trigger your script.

                                    1 2 Previous Next