Applescript, Filemaker and the Finder, where's the love?

Thanks to everyone who reads this, I’m really stuck here and fairly new to applescript, however I’m NOT new to filemaker.

I need to have filemaker save a PDF (easy part) to a specific path from a field, using a filename from a field. I can currently only save the PDF to one location dictated in the print script (Using a PDF Printer), but I’m unsure how to have the finder via applescript - using a filemaker text field for the path - navigate to the correct file path before assigning the file name - also from a filemaker text field.

The text fields are assigned already, and that part is working. I just need to navigate to a folder and save a PDF.

Any suggestions? I’m totally unsure if Applescript will even read from a filemaker field in this manner. I can already paste the filename into the save file dialog presented by the save to PDF print dialog, but I need a specified path to be assigned or I might as well do it manually - slow as heck with as many PDFs as I generate…

Any suggestions are extremely welcome!

Troy Way

Getting information from a field is not so difficult:

tell application “Filemaker Pro”

set x to current record of database 1
tell x
set mypath to cell “yourfieldnamehere”

end tell
end tell

I would personally grab the file out of the folder after you print and move it to your path and even change the name. I think I understand your question.

That does indeed pull the path I need.

Okay, now I have Filemaker creating the file, and I can set mypath to a filemaker field. I assume I can do the same for y and set it as the filename. Now I’m not familiar enough with moving files using applescript.

As well, what format should the filemaker path be in, in order for applescript to recognise it as a file path during the move/rename?

I apologize if these are noob questions. I’m rather new to applescript. The best script I have so far pulls field names from another database, and creates a filemaker 7 DB with matching fields in a table the same name as the referenced database. That one was fairly easy, my first night with applescript.

The path in FileMaker for AppleScript should look like a Mac path, such as:
Macintosh HD:Users:Shared:Export.pdf

The reason I chose the Shared folder above is that you can export from a FileMaker hosted file to that folder and it should work on client computers (unless some creative types have changed their hard drive name).

The AppleScript can then move the pdf to the desktop. AppleScript has no problem knowing their desktop.
move file “Macintosh HD:Users:Shared:Export.pdf” to desktop
(you still need to rename the file)

FileMaker cannot hard-code the desktop itself, 'cause the path to desktop includes the short user name, different for each.

Here is a complete script I use. You must be on a layout with the file name field with this simple script. Comment out the 1st and last lines to use within a FileMaker Perform AppleScript step (needed in Script Editior however):

tell application “FileMaker Pro”

 [b][color=blue]set[/color][/b] [color=green]sharedFolder[/color] [b][color=blue]to[/color][/b] "Macintosh HD:Users:Shared"
 [b][color=blue]set[/color][/b] [color=green]printPDF[/color] [b][color=blue]to[/color][/b] [color=green]sharedFolder[/color] & "Export.pdf"
 
 [b][color=blue]tell[/color][/b] [color=blue]current record[/color] [b][color=blue]of[/color][/b] [color=blue]window[/color] 1
      [b][color=blue]set[/color][/b] [color=green]fileName[/color] [b][color=blue]to[/color][/b] [color=blue]cell[/color] "FileName_"
 [b][color=blue]end[/color][/b] [b][color=blue]tell[/color][/b]
 
 [b][color=blue]set[/color][/b] [color=green]newFile[/color] [b][color=blue]to[/color][/b] [color=green]sharedFolder[/color] & [color=green]fileName[/color]
 
 [b][color=blue]tell[/color][/b] [color=blue]application[/color] "Finder"
      [b][color=blue]try[/color][/b]
           [b][color=blue]set[/color][/b] [color=blue]name[/color] [b][color=blue]of[/color][/b] [color=blue]file[/color] [color=green]printPDF[/color] [b][color=blue]to[/color][/b] [color=green]fileName[/color]
           [b][color=blue]set[/color][/b] [color=green]movedFile[/color] [b][color=blue]to[/color][/b] [color=blue]move[/color] [color=blue]file[/color] [color=green]newFile[/color] [color=blue]to[/color] [b][color=blue]the[/color][/b] [color=blue]desktop[/color] [b][color=blue]with[/color][/b] [color=blue]replacing[/color]
           [color=blue]open[/color] [color=green]movedFile[/color]
      [b][color=blue]end[/color][/b] [b][color=blue]try[/color][/b]
 [b][color=blue]end[/color][/b] [b][color=blue]tell[/color][/b]

end tell

Ahha! I see where you’re going with this now I think.

Now couldn’t I do this to have it save to a specific path from the filemaker record?

— Modified to use the Perform Applescript step —

        set sharedFolder to "Macintosh HD:Users:Shared" 
 set printPDF to sharedFolder & "Export.pdf" 
  
 tell current record of window 1 
      set fileName to cell "FileName_"
                   set filePath to cell "savepath"
 end tell 
  
 set newFile to sharedFolder & fileName 
  
 tell application "Finder" 
      try 
           set name of file printPDF to fileName 
           set movedFile to move file newFile to filePath with replacing 
           open movedFile 
      end try 
 end tell 

In this configuration I have assigned a field to filepath and then told the finder to move the file to the filepath - which is assigned in my client record in filemaker. basically I want to generate monthly PDF files automatically and have them save into a client’s folder on my hard drive with the proper name - it looks like that might work…Your recommendations?