10 Replies Latest reply on May 5, 2010 6:47 AM by flamecoder

    Insert Picture using a script

    flamecoder

      Title

      Insert Picture using a script

      Post

       

      Hello everyone,
      I want to be able to insert pictures using AppleScript to automate the process. I can easily have AS insert a link to the image such as...
      set field "NameOfField" to "Path:To:Image.png"
      But I want the actual image put in the database and not just the reference to it. I need to create some kind of script in FileMaker to do the insert picture with the "Store as a reference only" box unchecked. I will then call the do script command from AS to run the filemaker script. I'm new to FileMaker and nothing seems to work that I'm trying here.What I have so far is a text field that contains the file path of the current image I want to insert and I place this in a variable.
      Set Variable [$PathToImage; Value:TableName::FieldName]
      Now I want to use what's in the variable as a file path to insert the picture.
      Insert Picture ["$PathToImage"]
      However this doesn't work... Can anyone help me out please!!!
      Thanks



        • 1. Re: Insert Picture using a script
          FentonJones

          Your idea is sound, to create a dedicated FileMaker script to do the actual Insert Picture, after calling it from whatever AppleScript got your file. I would control the process from a FileMaker script, not an external AppleScript, unless that is required for other reasons. There are a few rough spots (1st time around).

           

          1. An AppleScript Mac syntax file path looks like: Macintosh HD:Users:fej:Desktop:Picture.png

          A FileMaker syntax path (for an image) looks like: imagemac:/Macintosh HD/Users/fej/Desktop/Picture.png

           

          You need to use the FileMaker syntax file path when you Insert Picture. The only way Insert Picture will accept it is if you put it into a script Variable first.

           

          The only way AppleScript can tell FileMaker what the Mac path is to set it (as text) into a text field (global likely). There are gotchas to do with that, passing data to/from AppleScript, but I'm assuming you know these, as you're using AppleScript. If not, let me know. Let's say you've had AppleScript put the Mac syntax full path (as text) into a "gMac_path" global field.

           

          Set Variable [ $filepath; "imagemac:/" & Substitute ( gMac_path; ":"; "/" ) ]

          Go to Field [ container field ] (must be on layout)

          Insert Picture [ container field; $filepath ]

          Commit Record

           

          • 2. Re: Insert Picture using a script
            flamecoder

            Hi Fenton,

            I am able to convert the Mac path to forward slashes in AppleScript by using the Posix Path.

            What I don't understand is how you put the container field & variable name into the Insert Picture portion of the script.

             

            In FileMaker 10, I go to File > Manage > Scripts then Edit my script.

            I choose Insert Picture and move then Specify...

            Trying to type in container field & variable name will not let me save. Can you manage a script another way??

             

            Thanks for your help.

            • 3. Re: Insert Picture using a script
              FentonJones

              There are 2 "Specify" buttons, one for the Field, one for the Variable. You pick the field in the 1st specify, and type the variable's name ($path, no quotes) in the 2nd.

              • 4. Re: Insert Picture using a script
                flamecoder

                I do not have 2 "Specify" buttons. Using FileMaker Pro Advanced 10.0.v3 on Mancintosh. Also check FileMaker Pro 10 on another Mac & Windows machine, same thing.

                I'm only seeing Script Step Options "Store only a reference" checkbox, "Specify source file" checkbox, and "Specify..." button (last two options open the same "Specify Picture File" dialog with an "Add File..." button to choose a file and a text area to type or display "File Path List". Anything I type in wants to have a file path syntax and will appear in the Insert Picture [ ] brackets in quotes.

                 

                Are you using version 11???

                • 5. Re: Insert Picture using a script
                  aammondd

                  drop the field name out of the Insert Image step and just use  the variable name. It worked for me

                   

                  Set Variable[$path; "path"]

                  Go to Field[Table::Image]

                  Insert Picture[$path]

                  • 6. Re: Insert Picture using a script
                    flamecoder

                    I have tried this and it still will not work on my end. My variable in the Insert Picture [ ] step is in quotes. Doesn't this mean it will treat it as a string and not a variable. When I run it I get "The file "$PathToFile" could not be found and is required to complete this operation."

                     

                    I'm thinking the quotes need to go for the variable to pass its contents correctly...

                    • 7. Re: Insert Picture using a script
                      aammondd

                      Yes its in quotes thats just FM saying this is what was specified.

                       

                      If its failing then the problem is with the path string.

                       

                      All I did was set the variable to "imagemac:/volume/folderpath/filename" which could be done in a calculation manner as well

                      You might want to throw the variable out in a dialog box to see if your computation isnt coming out right

                       

                       

                      • 8. Re: Insert Picture using a script
                        FentonJones

                        Sorry, re: 2 "Specify" buttons. I was looking at an Insert File step, and didn't realize the older Insert Picture did not have the "specify" field button (it should :-).

                         

                        But, yes, no quotes around variables. They are more like fields in that way, ie., a FileMaker object, not text: $path

                         

                        And yes, you'd want to see your path. It is very easy to end up with a double slash, or missing one, or missing the "imagemac:/", etc.; easy to see.

                        • 9. Re: Insert Picture using a script
                          aammondd

                          The script step will put the quotes around it you don't  when you manage scripts

                          Sorry if that wasn't clear.

                          Just type $variablename into the box rather than going to the add dialog

                          • 10. Re: Insert Picture using a script
                            flamecoder

                            Alright I found my problem. Since my images were on a mounted server when I performed my Posix Path in AppleScript to make the path acceptable for FileMaker with the slashes, it was adding Volume to the front of the file path. Removing this solved the problem and I'm able to insert my pictures using AS and the do script. Cool..... Thanks for the help guys!!! This is just the beginning of my database project. I'm sure I'll be back for more advice...