Jump to content

Telling Preview to open a PDF


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

Recommended Posts

Well, let me start by saying that I know almost nothing of Applescript, but I wrote a little script based on different posts I've read. And I'm not surprised to find that it doesn't work.

All I want it to do is have FileMaker open a pdf when the container is clicked based on the path field. I don't know what to do differently than what I have tried. Before the most recent attempt, it would just say "Object not Found", but now it pretens to do what I asked but really doesn't do anything.

If anyone could give me a helpful push in the right direction, it would be extremely helpful and very much appreciated.

Thank you!

Amber

employeeinfo.fp7.zip

Link to comment
Share on other sites

PS: This is what I am trying to use instead of calculated applescript, and it's the one that says 'object not found':

tell current record of window 1

set thefile to cell "path"

end tell

tell application "Preview"

open thefile

end tell

Link to comment
Share on other sites

[if you can upgrade to FileMaker 8, then you can use a Script Variable to export directly to any accessible path, incl. using Get(DesktopPath), and [x] Open file after exporting; so much of the below may not be needed.]

The first thing that's wrong is a FileMaker path is not the same as an AppleScript path. AppleScript still uses the old Mac paths, with the colon as a separator. It can also use Unix POSIX paths, within: do shell script "commands". But neither of these are FileMaker paths exactly.

The second point is that you need to export the PDFs to an accessible location. If one user inserts a file, another user on the network is not going to be able to export to the original file path. It is not available, because most document file paths, including the Desktop, contain the specific short user name.

There are folder paths which do not contain the user name and which should available to everyone. The two I use are:

Macintosh HD:Users:Shared:

and

Macintosh HD:private:tmp:501:TemporaryItems:

The 2nd one (weird though it looks) is useful for exporting FileMaker embedded PDFs, because then there's no extra file to clean up. It will be deleted by the operating system (when you restart I believe). If however you wish to keep the file after exporting, then the Shared folder is a better location to export to. You can then use AppleScript to move it the Desktop, which is a more convenient location (but not accessible to FileMaker 7).

So, the FileMaker path (for a Mac) would look like:

filemac:/Macintosh HD/private/tmp/501/TemporaryItems/File.pdf

"File.pdf" is just a generic name to use for the exported file, since it must be a fixed name in FileMaker 7.

This works, but it looks better if you rename the file to its original name, which you have from GetAsText(Container), so that it shows in the file's Title bar. The Finder can rename the above file before opening it. This has one glitch however. The Finder cannot rename a file to a name already existing in a folder. So if you export the same file twice (between restarts), you'd get an error. There are 2 different solutions to this. The easiest is to assume that it is the same file, so you don't really need to export it or rename it, just open it. You can check if the file's already there first, and if so just open it (ie., don't even Export). This is most efficient.

Another approach would be to delete the existing file first, then rename the export. Useful only if the pdf file is constantly changing, and you want the latest version. Otherwise a little clunky. You could use a do shell script "rm" command to bypass the Trash however.

I left scripts for all of the above in the file. Kind of confusing. But I'm only using the "Exists" one, 'cause it's the best.

I also messed with your labels in the portal. In a portal with "allow creation of related records" turned on for the relationship you end up with buttons in the blank row, such as a Delete button (which does nothing there and confuses people). It seemed to me that you would want the button "Add" to say "Edit" for the rows that already have a file. So I created calculations in the PDF table to do that. Actually it's much easier to just turn off "allow creation" and put an "Add File" above the portal.

I changed your little window a little also. I guess I'm bored today ???-]

Link to comment
Share on other sites

Forgive me for perhpas missing it, but is there a file that you uploaded that I am not seeing? I know I got virtually no sleep last night, but I don't see a file to download and poke through. ???]

Thanks, Fenton!

Amber

PS: We will be upgrading soon, I just don'tknow how soon. You know how bosses are. Hahaha!

Link to comment
Share on other sites

Oops! Sometimes I forget to hit the "Add" button in that forum dialog for attaching the file. Also, I'm afraid that after posting I decided I would keep the file as an example. So I deleted your logo from the layouts. You'll need to paste it back.

Or just import the script(s) you want (as I said, there are several, but the best one is attached to the button).

Also, you can either use my little layout feature of changing the name of the button, by hiding the "Add" button on the existing records. It is a little tricky, as it uses a related calculation field with a global container to actually hide; which just has the background color in it. In other words, there's 3 objects on top of each other, in this order:

1. "Add" button, plain old layout text (only shows on last empty row)

2. Calculation field with global container result (only shows on existing related rows)

3. Calculation field, = "Edit" ( ditto )

Or just put an "Add" button above the portal. Much easier.

employeeinfo_fej.zip

Link to comment
Share on other sites

I finally got a chance to go through the file today. I am always amazed. And subsequently always dumbfounded. I am still convinced that one day I will be good at FileMaker as well, but we shall see. :)

How do I tell it the right path to use for the temp file? when I type "Macintosh HD:Users:Shared:temp:" into the spot where it says (path to temporary items), I get an error that the file could not be created on this disk, and then that it can't get that file. I'm sure I've missed something obvious, but just the same.

Link to comment
Share on other sites

If you forget, AppleScript can tell you the paths to 'special folders'. Run this line in Script Editor:

path to temporary items as text

(P.S. Of course that's a 'Mac' path. Change ":" to "/", and add "filemac:/" at the beginning for a full FileMaker path.)

Edited by Guest
PS
Link to comment
Share on other sites

  • 3 months later...

I've tried using the path to this temporary folder in a custom function like this:

docs_path = "Macintosh HD/private/var/tmp/folders.501/TemporaryItems/";

which is based on Script Editor's return of: "Macintosh HD:private:var:tmp:folders.501:TemporaryItems:", but Filemaker keeps returning the following message:

"FILENAME.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 am logged in as an administrator of this computer, so there shouldn't be any permission problems.

Any ideas on how to get this to work? (I'm really trying to hide delete the .pdf file that's is created automatically (currently on the desktop) when I send a .pdf by email using a Filemaker script.

Link to comment
Share on other sites

Are you adding the "filemac:/" prefix? And the file name? In any case in FileMaker 8 you don't really have to use AppleScript to put a file on the Desktop. There is a new Get (DesktopPath) function which returns the folder path (including the slashes at both ends).

You can use Set Variable script step to put this into a variable (which you name, beginning with 1 or 2 $), which can then be used in the Export path. 1$ is local to the script. 2$$ is global.

Set Variable [ $ExportPath; "filemac:" & Get (DesktopPath) & "filename.pdf" ]

Export Records [ $ExportPath ]

[P.S. You can use the Get (SystemPlatform) to fork for platform. PC's want "filewin:" But otherwise it's the same.]

Link to comment
Share on other sites

  • 2 weeks later...

I have no problem having the .pdf that's created appear on the desktop using the steps you described. What I'm trying to do is not have the file seen at all. It just needs to be attached to an email and once it's sent, I'm done with it. I'd rather not have to go to the desktop every time and delete each file from the desktop.

Here's the variable code I'm trying to use:

Let(

[

file_name = Substitute ( Enter Orders::EmailAttachName ; ".pdf" ; "" ) & ".pdf"; // See note below

docs_path = "filemac:/" & "Kevin's G5/private/var/tmp/folders.501/TemporaryItems/";

full_path = docs_path & file_name;

win_path = """ & Right( full_path; Length( full_path ) - 1 ) & """

];



full_path



)

But I just keep getting the same message: ""xxxxx.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."

The other option, which I can't get to work either, is to have the .pdf created on the desktop and then deleted automatically after Filemaker attaches it to a new email. But I haven't been able to find the right combination of Filemaker script steps and/or Applescript to make that happen.

Link to comment
Share on other sites

This topic is 6677 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.