1 2 Previous Next 16 Replies Latest reply on Aug 7, 2012 2:59 AM by North2Alaska

    Save records as PDF

    North2Alaska

      I'm having some difficulty with the Save Records as PDF script step. I get an error: “XXXXXXXXX.pdf” could not be created on this disk. Use a different name, make more room on the disk, unlock it or use a different disk.

       

      I've dug around on the net but haven't found anything that might help.

       

      • I first capture the path in a variable, $Path.

      Let (

      [

      CTS = Get ( CurrentTimeStamp ) ;

      TS = Year ( CTS ) & Right ( "00" & Month ( CTS ) ; 2 ) & Right ( "00" & Day ( CTS ); 2 ) & Right ( "00" & Hour ( CTS ); 2 ) & Right ( "00" & Minute ( CTS ) ; 2 )

      ];

      GetPath ( "Desktop" ; "Royalties_" & TS ) )

       

      Where GetPath returns the path tot the Desktop and appentds the folder name of Royalties with a date and time stamp.

       

      • Next I create the above folder and open the folder wide open with Perform AppleScript

      "do shell script " & Quote ( "mkdir " & $Path & "; " & "chmod 777 " & $path )

       

      • All works so far. Next I get the name for the file (where the name of the file is like LastName_FirstName and build a full path.

      "FileMac:" & $Path & "/" & Substitute ( $Name ; ", " ; "_" ) & ".pdf"

       

      • Finally, I try to save the file

      Save Records as PDF [Restore; No dialog; "$file"; Records being browsed]

       

      And this is where I get the error. The interesting thing is if I don't give it a full path and just give it the name of the file and nothing more, it creates the PDF just fine in the same folder as the solution is in. But I'll have a couple hundred of these files to create and I would like to keep them together and not polute the solution folder.

       

      Any help would be appreciated.

        • 1. Re: Save records as PDF
          taylorsharpe

          Try this:

           

               Let ( [

                         CTS          =  Get ( CurrentTimeStamp ) ;

                          TS           =  Year ( CTS ) & Right ( "00" & Month ( CTS ) ; 2 ) & Right ( "00" & Day ( CTS ); 2 ) & Right ( "00" & Hour ( CTS ); 2 ) & Right ( "00" & Minute ( CTS ) ; 2 ) ;

                         Path = Get ( DesktopPath ) & TS

                    ] ;

                 Path

                 )

           

          I'm not sure about your custom function "GetPath", but the Get (DesktopPath ) is a native FileMaker function. 

           

          If this doesn't work, then you can check on permissions.  However, something is really weird if you as the user do not have permission to write to your own desktop. 

           

          FYI, if you want to manipulate files and folders (e.g., copy, paste, delete, move), there are quite a few plugins that do it.  I personally prefer the ScriptMaster one because the license is free, but it does involve opening a ScriptMaster file to determine which functions you want to turn on.  I usually do this in a Startup script so it is automatic. 

           

          Let us know how if this works or not.

          • 2. Re: Save records as PDF
            taylorsharpe

            Ooops, forgot that you set the calculation above (Let statement) = to a variable say $FullPath.  Then you do a:

             

                      Save Records as PDF ["$FullPath"; Records being browsed]

            • 3. Re: Save records as PDF
              North2Alaska

              GetPath is just a wrapper around the FM Get functions for desktop, file, documents, etc... and when run, will return the following:

               

              /Volumes/Master/Users/jesse/Desktop/Royalties_201208051238

               

              Which is the full path to the folder where I want to save the files.  Then I create the directory and open the permissions using the Perform AppleScript script step:

               

              "do shell script " & Quote ( "mkdir " &  $Path & "; " & "chmod 777 " & $path )

               

              Finally I append the actual file name to the end of the $path and append the "File:" or "MacFile:" either one but neither works.

               

              "FileMac:" & $Path & "/" & Substitute ( $Name ; ", " ; "_" ) & ".pdf"

               

              And this will produce something like:

              FileMac:/Volumes/Master/Users/jesse/Desktop/Royalties_201208051238/Doe_John.pdf

               

              So, all the parts and pieces are there to do it without a plugin, it just isn't working as expected.  One of the thoughts I had is with the new Mountain Lion and Sandboxing, if that could be an issue, but I just don't know.

              • 4. Re: Save records as PDF
                glennsingleton

                I like the data viewer for actually testing and seeing each step of what's going on.

                 

                If you say it is creating the folder, make that $$file and "watch" the value.

                 

                That way you can know the "full path" is exactly what you expect and you might have found a "new feature".

                 

                The other way, with a free plugin, just to test is to try the excellent BaseElements plugin and see if somehow the "do shell script" part is interferring with the save as pdf (I couldn't imagine why).

                 

                Very frustrating, good luck.

                 

                Glenn

                • 5. Re: Save records as PDF
                  taylorsharpe

                  I still suggest trying it with the Get ( DesktopPath ) like I suggested and let me know if that fails too since it is the standard FileMaker script step.  But it is up to you.  When things don't work as expected, it is good to try lots of different ways to achieve the solution. 

                  • 6. Re: Save records as PDF
                    North2Alaska

                    I've done it both ways now, with my GetPath CF and with Get ( DesktopPath ).  The data returned in the Data Viewer is slightly different. 

                     

                    GetPath : FileMac:/Volumes/Master/Users/jesse/Desktop/Royalties_201208051446/Doe_John.pdf

                    Get( DesktopPath ) : FileMac:/Master/Users/jesse/Desktop/Royalties_201208051446/Doe_John.pdf

                     

                    You can see that my wrapper function starts with /Volumes and that is necessary for the shell script in order to create the folder.  So, I set the $Path again with the FM built-in function.  I get the same results. 

                    • 7. Re: Save records as PDF
                      keywords

                      There is no indication in your post whether you are using FMServer, but if you are then you must have fmserver permissions set to read and write for any folder you want to save anything to.

                      • 8. Re: Save records as PDF
                        taylorsharpe

                        The filemac format is what is needed if you want to use a FileMaker function like Save As PDF.  I understand external functions like AppleScript and some functions in 3rd party plugins like it the way the OS gives a path, but the Save As PDF is a FileMaker function and that is why I recommended using Get ( DesktopPath ). 

                         

                        Regarding permissions, can you do this on another computer?  It is very rare for a User of a FileMaker client not to have write permissions to their Desktop path unless the destination path already has a file in that location with the same name and it is locked (e.g., open or in use).  Are you sure you don't have it open in something else?  Try changing the name to a new name (e.g., add a timestamp in the name path) and see if it works.  And of course if this is being run as a server script, I assume you know that files paths are all different than for a client, but I'm assuming not. 

                         

                        Give those a try and report back. 

                        • 9. Re: Save records as PDF
                          cortical

                          I have been using create dir, and clone ( or in the old days copy) file set, zip archive and remove originals , to various destinations for a few years.

                          2 paths are needed

                          if you are working on different partitions, a different path syntax is required for the mk dir  as well

                           

                          A - mk dir to user  sub dir

                          1) create dir under user path

                          /users/cortical/Documents/z_archive/archive_p079/ajb_B1968_20120806_0934_clone

                           

                          2) using get desktop will parse this, which does not work

                          /cortex/Users/cortical/Desktop//ajb_B1968_20120806_0937_

                           

                          and needs to be substituted to:

                          /Users/cortical/Desktop//ajb_B1968_20120806_0940_

                           

                           

                          B - create file etc under the created dir

                          3) under user path, single partition

                          /cortex/users/cortical/Documents/z_archive/archive_p079/ajb_B1968_20120806_0934_clone/

                          or to desktop

                          /Users/cortical/Desktop//ajb_B1968_20120806_0940_

                           

                          for multiple partiions add /Volumes prefix  ( subs

                          Substitute(  $_bup ; ["/Volumes" ; ""] ; ["/volumes" ; ""]  )    & "/"

                          // subn case sensitive

                           

                           

                          C - and add the path prefix and file suffix

                          $_platform =

                          Case(

                          Get ( SystemPlatform ) = 1; "filemac:" ;

                          Get ( SystemPlatform ) = -2; "filewin:" ;

                          )

                           

                          $_file =

                          Let([

                          F = Get ( FileName )

                          ];

                          F  & ".fp7"

                          )

                           

                          $_path =

                          Let([

                          F  =  $_file  ;

                          FP = $_bup_path

                          ];

                          $_platform  & FP &  F

                          )

                           

                           

                           

                           

                           

                          I was only doing a print pdf to desktop script last  night

                          $_path =

                          file:/cortex/Users/cortical/Desktop/PSN00001_first_last.pdf

                           

                          Note that the FM prefix

                           

                          to parse paths for checking, one can use terminal and just drag the  tergate onto the terminal window to get the path

                           

                           

                          I like the chmod include in the mk dir btw

                          • 10. Re: Save records as PDF
                            North2Alaska

                            No, not on server, so that possibility is out.  I'm just stumped.  Could I ask for a very simple example file.  Have a script create a folder on the desktop and save a record as a pdf.  If that works then I know it's something with me and I'll go through it again.  If not then some external problem exists and I can try to track that down.  Thanks for all the help and here's to hoping solving the problem...

                            • 11. Re: Save records as PDF
                              cortical

                              simple demo as requested, note for user on normal single partition

                              set the var $_volume value to your use case

                               

                              #CONTROL VARIABLES
                              #SPECIFY THE VOLUME NAME
                              Set Variable [ $_volume; Value: "/cortex" ]
                              #
                              #====================================================
                              #DST
                              Set Variable [ $_dst; Value:Substitute( Get ( DesktopPath ) ; $_volume ; "")  & "dst"
                              #
                              #====================================================
                              #PDF
                              Set Variable [ $_pdf_path; Value:Get ( DesktopPath ) & "dst" ]
                              Set Variable [ $_file_name; Value:"abc" & ".pdf" ]
                              Set Variable [ $_path; Value:"file:" & $_pdf_path & "/" & $_file_name ]
                              #
                              #
                              #====================================================
                              #CREATE DIRECTORY - DST

                              #====================================================
                              Set Variable [ $_shellCmd; Value:"mkdir " & $_dst ]
                              Set Variable [ $_script; Value:"do shell script \"" & Substitute($_shellCmd ; ["\"";"\\\""] ) & "\"" ]

                              Perform AppleScript [ Calculated AppleScript: $_script ]
                              #
                              #
                              #====================================================
                              #CREATE PDF IN DST
                              #====================================================

                              Save Records as PDF [ File Name: “$_path”; Current record ]
                              [ Document - Compatibility: Acrobat 7 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 ]

                              #
                              #

                              #====================================================

                              #TERMINATION

                              #====================================================

                              Exit Script [ ]
                              #

                              • 13. Re: Save records as PDF
                                taylorsharpe

                                Looks good other than I disagree that using Get ( DesktopPath ) doesn't work.  It may not work with a non-FileMaker function likein an AppleScript, but it clearly does with a FileMaker function like Save As PDF and I've done many a solution with it.  I also have to work in a mixed environment most of the time, so I really do all that I can to avoid AppleScripts.  And with plugins like ScriptMaster, there are few things for which I need something outside of FileMaker to solve my problems with file/folder functions such as copy, move, delete, zip, etc. 

                                 

                                Attached is a file I made on Mac OS X 10.7.4 and FileMaker 12v2.  I ran the script and it make the file.pdf report on my desktop.  Worked without a hitch. 

                                 

                                But I still do not know the answer to the original problem other than maybe permissions or there is a file already in that location or the file is locked by being open or something. 

                                • 14. Re: Save records as PDF
                                  North2Alaska

                                  @taylorsharpe  Thanks for the test file, but I am still using FM11.  Can I still use this file?

                                  1 2 Previous Next