jasonwood Posted July 26, 2004 Posted July 26, 2004 I'm trying to make an AppleScript that will change the document named rename.pdf to another name. I tried: tell application "Finder" activate set name of document file "rename.pdf" of folder "Desktop" to "hello.pdf" end tell to make it work, I have to add the full path... set name of document file "rename.pdf" of folder "Desktop" of folder "jasonwood" of folder "Users" of startup disk to "hello.pdf" but this won't always run on a machine with user "jasonwood". I also tried ..."Desktop" of folder "/~" of startup disk to "hello.pdf"
jasonwood Posted July 26, 2004 Author Posted July 26, 2004 Well, I figured it out, partly, with a little help from MacScripter, but I have a new problem. Here's where I am: tell application "FileMaker Pro" to set newname to cell "gTempName" of table "Preferences" of database "StoreOSNew.fp7" set filepath to (((path to desktop) as string) & "rename.pdf:") tell application "Finder" set name of document file filepath to (newname as string) end tell Applescript doesn't like my reference to the table. I'm improvising from a script I did in FMP5. How do I make reference to the correct table?
Fenton Posted July 26, 2004 Posted July 26, 2004 The general syntax works for me. One mistake is that "rename.pdf:" sounds like a reference to a folder not a file, probably you want to lose the ":" Otherwise, if you're sure you're getting an error from the first part, with the table reference, I'd check to make sure you don't have a zero found count, which messes up a call to a cell. Also check to make sure the file really has an ".fp7" extension; generally any error in typing the names.
jasonwood Posted July 26, 2004 Author Posted July 26, 2004 AH HA! Thanks for the reassurance Fenton, I was using "FileMaker Pro" when I should have been saying "FileMaker Developer". I have a copy of FileMaker 5.5 on the machine so that's probably why it did not allow me to make reference to a table. I would rather say "FileMaker Pro" though, so it would work right away on my clients machines. Otherwise, won't it pull up a "Where is FileMaker developer" dialog the first time they run the script? Would it be okay after that? I also encountered a problem due to the fact I did not have any records in the Preferences table, as FM7 allows you to work with global fields in a table with no records - apparently AppleScript does not! Everything else works but I'll remove the for good form - I wasn't sure what it was, just copied it from an example. I'M SO EXCITED! IT WORKS!
Fenton Posted July 26, 2004 Posted July 26, 2004 ":" at the end of a file path means "folder" not "file," so it's important. You don't usually need a "tell FileMaker ..." (with its "end tell") inside a Perform AppleScript step. Best not to. This makes it portable. When run from the current file it knows who it is. Not so from Script Editor (which will tend to recognize whoever is running, maybe). Your script could be shortened (in Perform AppleScript step) set newname to cell "gTempName" of table "Preferences" of database "StoreOSNew.fp7" set filepath to (((path to desktop) as string) & "rename.pdf") tell application "Finder" set name of document file filepath to newname end tell
bruceR Posted July 27, 2004 Posted July 27, 2004 How did the PDF file get created? Was this a PDF print job from Filemaker? If so, consider this: FileMaker automatically names a PDF file with the name of the window. With FM7, you have control over the name of the window. So you can create an automatic script that names the window, "prints" the PDF to the desktop, and resets the window name.
Fenton Posted July 27, 2004 Posted July 27, 2004 Hi Bruce. This is a great idea. Unfortunately, after getting it to work once I can't get it again. Is there a specific sequence of actions? When I'm setting it up, in order to Save As PDF, in the Print dialog, I have to give the file a name. The default is the open window, but it's "Edit Script," 'cause that's the open window at that point in time. It will not let me leave it blank; the Save button dims. I've tried a brand new script step. No dice. But I did get it to work once. I just can't seem to recreate the sequence.
bruceR Posted July 27, 2004 Posted July 27, 2004 Darn. I relied on an interesting bit of info passed on by somebody else that turns out to be wrong. Well, back to plan B, which was my original plan A - pass the file name via clipboard and use PDF Services. THAT setup can be saved for sure, I've done it. Here's a writeup I posted on another list: In OSX, there is a feature call PDF Services that allows you to script the creation and routing of PDF documents. The following instructions show how to create a PDF, save to desktop, and name it using the value on the clipboard. Your Filemaker script would set the clipboard value before printing. Inside your user Library folder you need to create a folder called PDF Services. Make sure this folder exists. Then using applescript script editor to save this script in the PDF Services folder and name it SaveUsingClip -- start script 1 property targetFolder : path to desktop folder on open these_items repeat with i from 1 to the count of these_items copy (the clipboard) & ".pdf" to newName set the clipboard to "" set this_file to item i of these_items tell application "Finder" set name of this_file to newName duplicate this_file to folder targetFolder with replacing end tell end repeat end open -- end script 1 In your FileMaker documents, create a print script like this: Print to PDF #Start Perform applescript: property cellName: "InvoiceID" -- or whatever you choose get data cell cellName of current record of document 1 set the clipboard to result as unicode text -- I'm assuming you're smart enough -- to pick a field that doesn't have too much text #Standard ScriptMaker steps: Page Setup [Restore] Print #end Leave dialog ON the first time you run the script. In the print dialog, look for the new PDF Services dropdown in the bottom of the dialog and choose SaveUsingClip. Go back to your script and turn off the dialogs. Save the script and replace page setup. The script can be modified to pass a target folder dynamically, etc. You don't need to use the applescript method of putting the value on the clipboard - it just allows you to do this without using the FileMaker copy command and therefore without requiring a field to be on a layout.
Fenton Posted July 28, 2004 Posted July 28, 2004 Yes, that works very well. Here's one last twist (for PDF Nirvana :-) I was wondering if this would work on a client machine, that had the same script in its PDF Services folder (for current user). Not quite. It runs. But no PDF appears on the Desktop. Upon searching I found it, in a private/tmp/number folder, with the name "Print Job.pdf" It's the right file, but it didn't move it to the Desktop or rename it. The correct name IS on the clipboard though. Obviously it's losing the action somewhere. If this could be made to work it would make this very useful in the real world (rather than just on my own little computer). If you turn on the dialog, the client could always save it on their Desktop, and rename it manually. But that's clunky (in comparison). I'm not the greatest on knowing the how-to's and limits on networks.
bruceR Posted July 28, 2004 Posted July 28, 2004 That should not be happening the way the script is written but I'm not sure what you did. Did you copy and paste the text from the previous message - did you leave "path to desktop folder" as supplied - or did you type in a path? Actually there is a better way to do it anyway. Change: property targetFolder : path to desktop folder to set targetFolder to (path to desktop folder from user domain)
Fenton Posted July 28, 2004 Posted July 28, 2004 I'm trying it from a client machine, which has the exact same script, in a similar PDF Services folder in the user's Library. It "prints to pdf," but leaves the file in the tmp folder, named "Print Job.pdf." Have you gotten this to work from a client computer on a hosted file? That's where I'm having trouble. It works fine on my host computer. Oh, I get it now. It can't pass the variables in the Perform AppleScript step from a hosted file to the client computer (at least not the usual way, and not a way I know). Duh. Too bad though.
bruceR Posted July 28, 2004 Posted July 28, 2004 I don't follow you. There isn't any variable passing. It works on hosted files, just tested. However: there are two places you can create a PDF Services folder, and you can actually use both. You can create a PDF Services folder in Library, as well as users/library. I put my the applescript app there in Library/PDF Services. Just tested this in an FM6 file and FM7, it works fine across a network.
Fenton Posted July 28, 2004 Posted July 28, 2004 I got it working. It was "just one of those things." For some reason the client computer just wouldn't use the PDF Services, though I know it used to, not from any application or any document. So I did all kinds of things, threw away many things (Preference Panes, etc.), updated from 10.3.3 to 10.3.4. Still no dice. Finally I tried saving the script as an app. That worked. So I went that route. But it was slower, and a bit ugly (launching the app), and I knew it wasn't supposed to have to work that way. So I tried it again as just a script, and it worked, whether it was in the System Library or User Library. I remember having a bad crash once on that machine, trying someone else's "Send PDF with Eudora" script in PDF Services; so I'll guess that something was "bent," but got straightened out. Anyway, it works! Which means you can now, on Mac OS X automate saving a PDF onto the Desktop on a client machine. Now I'm going to try and add emailing it (with Mail) from there to the script; that was the ultimate goal. Thanks for your patience. Sometimes it's necessary for someone else to say, "yes it works."
Recommended Posts
This topic is 7421 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 accountSign in
Already have an account? Sign in here.
Sign In Now