1 2 Previous Next 15 Replies Latest reply on Jun 1, 2010 9:39 PM by RickWhitelaw

    Get(TemporaryPath) problem

    RickWhitelaw

      Summary

      Get(TemporaryPath) problem

      Description of the issue

      PMPA 10v3Mac OS X 10.6.2 After puzzling about the incorrect info in the help file regarding the path the function returns, I found a KB article that explained that Get(TemporaryPath) returned: /My Drive/private/var/folders/4D/4DANsW03HG0DdU1dyriORE+++TI/Cleanup At Startup/S10/.This presents a problem when scripting in many environments (I suspect) but certainly from a bash shell. "Cleanup At Startup" has spaces in the name, and although, when FM is running (and the Temp Path exists), I can "Go to Folder" from Finder and get to the right directory, shell scripts choke and I'm almost certain it's because of the spaces. Looking around at directories in "var" I'm hard pressed to find a name with spaces. It would be a good idea to have this Temp directory named "Cleanup_At_Startup". With spaces, the shell script throws an error at the first space. Directory" ./ /./ .etc. . .Cleanup" does not exist. I could script the creation of the directory with the underscores, but FM numbers the final "S" itself, so I'm thinking it would be futile. What I'm trying to do: Print pdf documents from the TemporaryPath via shell scripting (calculated Applescript "do shell script"). .FMPA saves the pdf files properly but the path cannot be accessed by Unix. This all works fine using the Desktop as a destination (no spaces) but requires the "lpr-r" option to automatically delete the file. I want to avoid this by using the TemporaryPath. The directory naming should not include spaces. RW

        • 1. Re: Get(TemporaryPath) problem
          philmodjunk

          Many system scripting tools have a way to handle spaces in file paths by enclosing the text in quotes or something. Don't know if that's possible with Bash, (I'm on windows here), but I'd look into that as a possible work around.

          • 2. Re: Get(TemporaryPath) problem
            RickWhitelaw

            Thanks Phil,

             

            I've tried the Quote function. Also Substitute(path;" ";"_") and regular escape quotes. So far no luck. However, you're probably right . . . I just need to know more about the syntax.

             

            RW

            • 3. Re: Get(TemporaryPath) problem
              philmodjunk

              Those sound like filemaker functions. I'm suggesting you look at what to do in Bash that will allow you to refer to a folder or file name with spaces. There's usually a way to do this when working with a system script.

              • 4. Re: Get(TemporaryPath) problem
                RickWhitelaw

                They are FM functions. I'm using a calculated Applescript to pass the shell script. In any case, the way to do it is to set up a variable $FileName which would be Get(TemporaryPath)&"myfile.pdf" then, in the  Applescript which launches the shell script, enclose the variable in quotes. The OS accepts that . . . no more errors thrown. Now, if it would print! Doh!

                 

                It's a bit odd, because although the variables are evaluating correctly and the Applescripts produce proper shell scripts, the system works flawlessly when the content of the variables is "spelled out", but sometimes does nothing when executed using the variables. It may be a question of speed. The printer may need a pause.

                 

                Rick.

                • 5. Re: Get(TemporaryPath) problem
                  philmodjunk

                  That's missing my point, I'm afraid.

                   

                  If a directory in your path has spaces such as "Cleanup At Startup", changing your path to eliminate spaces or substitute a different character changes your path to point to a directory that doesn't exist.

                   

                  The point I am trying to make, is that directory and filenames with spaces are a very common occurrence in both mac and windows systems. Thus, most system scripts have some form of syntax that handles such an issue. I suspect that your system script (first you meantion "bash" and now you refer to applescript?) has some method of doing this. I can't tell you what it is as I'm not up to date on mac system scripts, but strongly suspect such a method exists.

                  • 6. Re: Get(TemporaryPath) problem
                    RickWhitelaw

                    Hi Phil,

                     

                    My posts must seem almost as convoluted as the method of getting FM to execute a shell script. The method: Perform Applescript (calculated). The main Applescript command used is "do shell script" and all that follows must evaluate as text that the shell will interpret correctly. The shell does not like spaces in file names. So, I do get your point and, as I described, I've found a way to deal with the spaces. Create a variable for the file path, and in the Applescript "description" of the shell script enclose the variable in quotes. It works. I can see that, in a way, it seems strange(as in: why does this work?) since the shell is still seeing spaces and it would be better perhaps to re-write the code in using syntax more native to the shell.

                     

                    It's needlessly (in my opinion) complicated getting anything done this way. The sheer number of quotes needed is a pain. Of course, all spaces in the shell script must be &" "& etc. The entire shell script after The AS command "do shell script" must be in quotes as well, so the Quote function is needed to wrap the whole thing. I'm not suggesting FM is solely at fault here. After all, getting FM to talk, using FM variables, to Applescript which then has to talk to the OS or shell,  can't be expected to be as simple as writing a script in FM.

                     

                    RW

                    • 7. Re: Get(TemporaryPath) problem
                      RickWhitelaw

                      One more wrinkle which may actually be the real cause of the problem . . . when FM saves a file (pdf) to the TemporaryPath it wants to see: /DriveName/private/var/folders/etcetera/etcetera . . .

                       

                      What Unix expects to see when retrieving or printing the file is the TemporaryPath without the drive name.The first "/" reads as "root" ( in directory hierarchy).

                      I'm playing with a way to format the variable in this way:

                       

                      "/"&Right(Get(TemporaryPath);Length(Get(TemporaryPath)) - Position(Get(TemporaryPath);"/";Length(Get(TemporaryPath));-8))&"worktemp.pdf"

                       

                      This evaluates as 

                       

                      /private/var/folders/4D/4DANsW03HG0DdU1dyriORE+++TI/Cleanup At Startup/S10.2/worktemp.pdf

                       

                      and doesn't throw an error.

                       

                      RW

                      • 8. Re: Get(TemporaryPath) problem
                        RickWhitelaw

                        I've discovered that FM does not always establish a TemporaryPath. Sometime it does, and what I write actually works.  In at least half the instances, however, FM fails to establish a TemporayPath. I assume that once FM is launched that a TemporaryPath is established. Apparently this is not the case. I've been de-bugging my scripts, and am able to check as to the existence of the TemporaryPath as I go. As often as not, the TemporaryPath simply does no exist. This qualifies as a bug as far as I'm concerned.

                         

                        RW

                        • 9. Re: Get(TemporaryPath) problem
                          TSGal

                          RickWhitelaw:

                           

                          Thank you for your post, but I'm unable to replicate the problem.  I have several scripts that use Get (TemporaryPath), and prior to each instance, I've placed a "Execute Script" that goes to a new layout, adds a record, and sets the field to Get (TemporaryPath) and returns to the original layout.  That new table has an entry in each record.  I've also hosted this file with FileMaker Server 10, and it also works correctly.

                           

                          I don't doubt this is happening to you, but I need a way to replicate the problem before sending it to Development and Testing.  Is there anything you notice just prior to the failed Get (TemporaryPath) that may provide a clue?

                           

                          TSGal

                          FileMaker, Inc.

                          • 10. Re: Get(TemporaryPath) problem
                            RickWhitelaw

                            Mac OS X 10.6.2

                             

                            Try this to replicate. Write a script that saves a pdf to the TemporaryPath. I use a variable ($filename) for the file name, defined as : Get(TemporaryPath)&"myfile.pdf"  .  Run the script in the debugger. After the script has saved the pdf, use the Finder "Go to folder" command, specifying "Cleanup At Startup". Sometimes the folder exists, and other times it doesn't.

                             

                            RW

                            • 11. Re: Get(TemporaryPath) problem
                              TSGal

                              RickWhitelaw:

                               

                              Using Snow Leopard (10.6.2), I am able to replicate the problem when using "Go to Folder" from the Finder.  However, if I use the utility "Terminal", the "Cleanup At Startup" folder is definitely present.  I can then go into the S10 folder and see the PDF file.  Therefore, I would not rely on the "Go to Folder" command in the Finder.  I'm not able to replicate the problem on Leopard, so it may be a Snow Leopard issue.

                               

                              TSGal

                              FileMaker, Inc.

                              • 12. Re: Get(TemporaryPath) problem
                                RickWhitelaw

                                Thanks,

                                 

                                I just tried it in the command line Terminal and, as long as the drive name is not the first directory, it works. The path must start with "/private". As well, "Cleanup At Startup" must be in quotes to escape the spaces. So the "Go to folder" command is the culprit.

                                 

                                Much appreciated,

                                 

                                Rick.

                                • 13. Re: Get(TemporaryPath) problem
                                  RickWhitelaw

                                  TSGal,

                                   

                                  Thanks once again. I've sorted this out and it turns out it may be the last stumbling block I've encountered (Hah!) in my quest to develop a truly dynamic Multi-printer system for my solution.The result of  "Get(TemporaryPath)" must be parsed differently for FM and Unix. Below is a bare-bones printing script that does not use the Print script step, and it works. The only "non-generic" element is "Print_Prefs" which is simply a table in the solution which matches printers with tasks. "$FilePath" must be declared twice; once for FM and once for the shell. Unix doesn't want to see the drive name and won't recognize a path that begins with it (as far as I can tell). This works on Mac OS X 10.6.2 with FMPA 10v3. I post it in case there are others who are looking for a workaround to the limitations of FM with multiple printers. To try it out as is, simply define $PRINTER as Get(PrinterName), or to be super-safe, Sustitute(Get(PrinterName);" ";"_") and change Go to Layout to a layout of your choice.

                                   

                                  Print: Print_WorkSheet

                                  Go to Layout [ “Work Report” (Production Info) ]

                                  Print Setup [ Orientation: Landscape; Paper size: 8.5" x 11" ]

                                  [ Restore; No dialog ]

                                  Set Variable [ $FilePath; Value:"file:"&Get ( TemporaryPath) &"worktemp.pdf" ]

                                  Save Records as PDF [ File Name: “$FilePath”; Current record ] [ Document - Compatibility: Acrobat 5 and later ] [ Pages - Number Pages From: 1; Include: All pages ] [ Security - Printing: High Resolution; Editing: Any except extracting pages; Enable copying; Enable Screen Reader ] [ Initial View - Show: Pages Panel and Page; Page Layout: Single Page; Magnification: 100% ]

                                  [ Restore; No dialog ]

                                  Set Variable [ $PRINTER; Value:PRINT_PREFS::Printer_General ]

                                  Set Variable [ $FilePath; Value:"/"&Right(Get(TemporaryPath);Length(Get(TemporaryPath)) - Position(Get(TemporaryPath);"/";Length(Get(TemporaryPath));-8))&"worktemp. pdf" ]

                                  Perform AppleScript [ Calculated AppleScript: "do shell script" &" "& "("&Quote("lpr"&" "&"-P"&$PRINTER&" "&"-o" &" "& "sides=one-sided"&" "& "-o" &" "& "media=letter" &" "&"-o"&" "&"orientation-requested=4"& " "& "-#1"&" "&Quote($FilePath))&")" ]

                                  Go to Layout [ original layout ]

                                   

                                   

                                   

                                  RW

                                   

                                  Edit:

                                   

                                  Set Variable[$FilePath;Value:Substitute(Get(TemporaryPath);Get(SystemDrive);"/")&"worktemp.pdf"]

                                   

                                  would be safer than the above text in red in the event FMI changes the directory depth for the Temporary folder in other versions. This one simply removes the SystemDrive from the path no matter where else the path leads.

                                  • 14. Re: Get(TemporaryPath) problem
                                    ehall

                                    The Substitute method would remove every instance of the system drive name, not just the initial one.  This could be a problem in the (admittedly unlikely) case where the system drive shares a name with one of the other folders in the path.

                                     

                                    Just to be safe, I prefer this method of removing the system drive from the path:

                                     

                                    Set Variable [ $filePath; Value:Right(Get(TemporaryPath);Length(Get(TemporaryPath))-Length(Get(SystemDrive))+1)

                                     

                                    It simply looks at how many characters are in the system drive name and removes that many from the start of the temporary path (adjusted by one to preserve a leading forward-slash).

                                     

                                    1 2 Previous Next