Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

Script step to view a pdf file (not reference) in a container field.


This topic is 6124 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I have a simple table with 2 fields: "Invoice" and "image". "image" is a container field that holds a pdf file (not just a reference). Now that I have this table I can search for the "Invoice" record that holds the pdf file I want to view, select the "image" field, but I how do I get the pdf file to display on the screen. Originally I was storing only the reference in the "image" field, and I could display it by using Goto Field[select/perform]. Now that I'm actually putting the file in the container and not just a reference, it no longer displays. You guys showed how to do it with the reference, I'm hoping you can help me again.

Thanks very much.

Posted (edited)

Since you've got the file embedded (where you can't read it), you need to use Export Field Contents to write it out as an external file again, so it can be opened (in Preview or whatever your default PDF reader is).

You can fairly easily export it to your desktop, using the Get ( DesktopPath) function. Also, an embedded file's name is in the container field.

Of course then you've got the file on your desktop, which could be awkward, you just want to read it, but don't really want it there afterwards. You could just throw it away. But a cuter method is to export it to the temporary items folder, then open it.

This is easy on FileMaker 9, as it has a Get (TemporaryPath). Before 9 you can use AppleScript to get the temporary items path on a Mac, or calculate it on Windows. Caveat: I've included the Windows path, if anyone wants that, but I don't feel like starting Windows to test it right now. Let me know if doesn't work.

(P.S. Using the AppleScript path on a Mac requires that the _gTempPath field be on the current layout. So you'll have to switch to a layout with it on while running that step; then you can switch back.)

(P.P.S. You don't need AppleScript or FileMaker 9 to just export to your Desktop. And, in fact, there is an alternate method to the temp folder. Which is to write the file to the Desktop, open it, then overwrite the file with an empty export. That has the effect of deleting the file immediately. I don't remember if I've tried that. It sounds simple, but is a little creepy :-)

ContainerFile.fp7.zip

Edited by Guest
Posted

Thanks Fenton. This is GREAT! I'm able to display the file fine now. However, I'm not clear on methods to delete that you mention. I created a table with a blank text field and tried exporting that field to the pdf file in order to delete the pdf file. FM didn't like it, said the file was of unknown type or corrupt.

I'm working on trying the Temporary path method here in a minute.(I'm using FM Pro 8.5) What happens to files in the Temporary "Path"? Do they get deleted when the application closes, or computer shuts down or what?

I think I prefer the concept of the Temporary Path, but at this point I don't understand the first and last lines of the script, and I like to understand what I put in my programs:

-set tempPath to POSIX path of (path to temporary items)

and

-set cell"_gTempFolder" to tempPath

Thanks very much... again!

Posted

-set tempPath to POSIX path of (path to temporary items)

(path to temporary items) produces a reference to your user temporary items folder on your computer, in AppleScript syntax. It is probably:

alias "Macintosh HD:private:var:tmp:folders.501:TemporaryItems:"

Though it could be 502, etc. if you're not the only user on the computer, hence we use a dynamic reference.

The command POSIX path converts the above to a Unix style path (spaces are not escaped, but FileMaker doesn't care about them, so we don't bother):)

"/private/var/tmp/folders.501/TemporaryItems/"

Then, inside FileMaker, I add: "filemac:" & Get (DriveName) and a file name to get:

filemac:/Macintosh HD/private/var/tmp/folders.501/TemporaryItems/some file name.pdf

Alternately, you could just use FileMaker's Substitute() function, once you were in FileMaker, to replace the ":" with "/"; that may be simpler.

-set cell "_gTempFolder" to tempPath

whenever you see "cell" it means you're inside a "FileMaker tell block", which is the default in a Perform AppleScript step. If you try and run it inside another AppleScript application, like Script Editor, it would have to be:

tell application "FileMaker Pro Advanced"

set cell "_gTempFolder" to tempPath

end tell

But since we're inside a FileMaker Perform AppleScript step, we don't need or want that (partly because it requires explicitly naming the application, though I'll be the preceding would also work in FileMaker Pro; it would recompile for it, as they both have the same process id (or something like that).

Oh yeah, the temporary items folder is cleaned out whenever you restart the computer.

This topic is 6124 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.