9 Replies Latest reply on Dec 31, 2010 4:52 PM by manager12

    Setting a file path in a script



      Setting a file path in a script


      I'm creating a script to export a record as a PDF. Right now the script work with the Get(DesktopPath) function, however I would like to save the records exported from this script to a certain folder on my laptop. 

      How do I specify a file path other than the built in DesktopPath?

      I've attached a screen shot of what my script currently consists of.

      Thank you.


        • 1. Re: Setting a file path in a script

          There is no any get()  function to set for other path, but u can solve ur problem. Here u need only to write the address in the variable explicitly, and everything will remain same as u did.

          • 2. Re: Setting a file path in a script

            Here's an example for a folder on your desktop:

            Set Variable [$FileName ; Value: Get ( DesktopPath ) & "FolderName/" & "FileName.Extension"]

            Other more specific locations on your hard drive can be specified, but the details differ depending on whether you are using Mac or Windows.


            • 3. Re: Setting a file path in a script
              Thank you. I got it to export the file to a folder on my desktop. If I want it to export the file a folder within a folder on my desktop is there a way to do that? I'm using a Mac. I tried writing the path like this but I ended up with an error: Set Variable [$FileName ; Value: Get ( DesktopPath ) & "FolderName/InternalFolderName/" & "FileName.Extension"]
              • 4. Re: Setting a file path in a script

                Your format is correct, so you'll need to look at the exact text entered into the variable to figure out why it didn't work. You may want to temporarily add a show custom dialog step to display the contents of your variable so that you can try to spot the problem.

                • 5. Re: Setting a file path in a script

                  You might try adding the "filemac:" prefix, as yours is an "absolute" path (from the drive root). The result should look like:

                  filemac:/Macintosh HD/Users/fej/Desktop/FM/HTML_export.xsl

                  Also, FileMaker will not create folders like a Unix command would. So do the folders already exist?

                  • 6. Re: Setting a file path in a script

                    I think the problem may be that the folder inside of the folder on my desktop that I'm trying to save the file to is an alias. Is there a way to specify an alias in a file path or do I need to write my file path to the actual folder instead of the alias?

                    The actual folder exists in my home directory. Instead of using the Get(DesktopPath) function, can I just write out the entire filepath from the drive root? See below.

                     Set Variable [$FileName ; Value: "filemac:/Macintosh HD/Users/username/FolderName/" & "FileName.Extension"]


                    • 7. Re: Setting a file path in a script

                      Yes, you can write out the path, if you know it. FileMaker is not as smart as the OS about aliases. It will resolve them to their original file during operations like Insert. But only once, and it does not resolve it for other operations.

                      OOPS! The below does not work for an alias for a folder. In fact, the OS seems kind of dumb about these; their "info" says, "alias: false". So it would only work if you had an alias file in the folder, to a file in the real folder; which you could first resolve, then get the "container of".

                      If you find yourself in a situation where you really want to use "alias files", ie., you know where the alias is, but do not know where the original folder is, you can use a simple AppleScript to locate the original file.

                      I'm using a global field to set the resulting path into, as it's easier. It would need to be on the current layout however, for this simple syntax.

                      set alias_file to (choose file with prompt "Choose an alias file") as text
                      -- this line is just to get an alias file's path as text; you would need to pass it the path instead

                      tell application "Finder" to set orig_file to original item of file alias_file as text

                      tell application "FileMaker Pro Advanced"
                      set cell "z_gFilePath" to orig_file
                      save record
                      end tell

                      You would not use that first line; it is only so you could try this from AppleScript Editor. You'd pass the alias file's path to AppleScript instead, after reading it from a FileMaker field. Like this:

                      tell application "FileMaker Pro Advanced"
                      set alias_file to cell "AliasPath" of current record
                      end tell

                      You do not need the: tell app "FileMaker Pro" lines inside FileMaker itself, as it knows who it is; it's running the AppleScript. It's a little difficult to explain all this via text; but it is not hard to do, and is very fast in operation.

                      P.S. I'd rewrite it as above, but it is so darn annoying to have to redo all the HTML this dumb editor inserts.

                      • 8. Re: Setting a file path in a script

                        In case anyone wants to know :-], you can get the original folder by opening the alias folder, then getting the path to its window. It will likely flash for a split second.

                        set alias_folder to (choose folder with prompt "Choose an alias folder") as text
                        -- once again, you'd set this from FileMaker to your path

                        tell application "Finder"
                        open folder alias_folder
                        set orig_folder to folder of window 1 as text
                        close window 1
                        end tell

                        tell application "FileMaker Pro Advanced"
                        set cell "z_gFolderPath" to orig_folder
                        save record
                        end tell

                        • 9. Re: Setting a file path in a script

                          Thank you both, I got it to work!