Fenton Posted February 4, 2007 Posted February 4, 2007 Proof of concept, probably not much use, but perhaps interesting. Included is a small AppleScript droplet to Insert whatever image file is dropped on it into a container field of the current FileMaker record. It (should) work with either local or mounted volume files. It is too bad we do not have the ability to somehow have an AppleScript "hot spot" object on a FileMaker layout, which could do this internally. This file requires FileMaker 8+, because it uses script Variable file paths. [P.S. The skull smoking a cigarette is a Van Gogh painting.] Import_wDroplet_8.zip
Fenton Posted February 4, 2007 Author Posted February 4, 2007 While I'm at it :-] This file will Insert a graphic into a container field by using its URL file path; which you have to type or paste in first. It uses the "curl" shell script command to download and write the graphic file to your temporary items folder (where it will be automatically deleted when you restart); then Inserts that into FileMaker's container field. Import_w_cURL_8.zip
cmulgrum Posted February 9, 2007 Posted February 9, 2007 This has more application than you think. I have a project that requires the user to create a parent folder (the design name) and then drop JPG and Photoshop images in the folder with the same name as the parent folder. ie., DesignName Designname.jpg Designname_comp.psd Designname_sep.psd Wonder if this applet can be enhance to do more...Create the parent folder. Name the file with the proper suffix. It has to be file reference because we're talking thousands of images. I'm about to try out your script. Thanks for sharing your info!!!!
Fenton Posted February 9, 2007 Author Posted February 9, 2007 (edited) Yes, AppleScript can create a folder, rename and move a file. It is fairly easy to add a prefix to a file name. It is little more trouble to add a suffix; because the file name includes the extension; so you have to pull them apart, add the suffix, then put them back together. You would need to tell AppleScript the info it would need to do this. You can then call a FileMaker script to Insert Picture, passing the info it would need. You can also set the FileMaker container field directly from AppleScript, for a referenced picture. It's a little trickier however, to deal with PDF files. Here's a simple AppleScript test, to create a "Something" folder on your Desktop: set DT to path to desktop as string set folderName to "Something" set theFolder to DT & folderName & ":" tell application "Finder" if not (exists theFolder) then make folder at DT with properties {name:folderName} end if end tell The one below will rename a file, then insert it as a referenced file directly from AppleScript. You have to test for file type and/or extension first, as it only works with supported file types (and AppleScript doesn't know which unless you tell it). This script looks at file types; it's an older script; but often files do not have that anymore, so you'd want to post-check for the extension instead. Alternatively you can call a FileMaker script to Insert Picture. You would need an open FileMaker file and record, with a text field named "PictureName" on the current layout, as well as a container field named "Picture". This script is mostly to give you an idea how it would be done. tell application "FileMaker Pro Advanced" tell current record of current layout of window 1 set newName to cell "PictureName" set pictureFile to (choose file with prompt "Choose the picture to Insert and rename…" of type {"GIFf", "JPEG", "PICT", "TIFF", "PNGf", "PDF ", "8BPS"}) tell application "Finder" set theExt to name extension of pictureFile set theFolder to (folder of pictureFile) as string set renamedFileTxt to (theFolder & newName & "." & theExt) as file specification -- allows you to also insert PDF files set name of pictureFile to (newName & "." & theExt) end tell set cell "Picture" to (renamedFileTxt) end tell end tell (P.S. You can add "psd" to the list of extensions allowed, in the earlier Import wDroplet file.) P.S.2 to find out whether/what file type a file has, run this little AppleScript: info for (choose file) Edited February 9, 2007 by Guest info for
cmulgrum Posted February 13, 2007 Posted February 13, 2007 Thanks for the help Fenton. Can you tell me how to calculate applescript? I want to rename a file based on value of an FM Field. Script will be attached to a button. Thanks again Craig
Fenton Posted February 13, 2007 Author Posted February 13, 2007 1. Do you know what extension (.jpg, .png, etc.)? Because it's easier to rename a file if you already know its extension. 2. Where is the file? You must know the path to the file to rename it. My examples above either get this from dropping the file on the droplet, or by making you choose the file. But if you already know the path, from a field in FileMaker, then you can pass that to the AppleScript. 3. I almost always use AppleScript in a Perform AppleScript step. I almost never use it in a calculation field, unless it's dead simple. There are some advantages to calculation fields; but it can drive you a bit crazy escaping quotes marks. Also, I generally write the AppleScript in Script Editor first, as it has syntax coloring and better error messages. The disadvantage of Perform AppleScript is that you have to pass FileMaker values explicitly. Which means they have to be on the current layout, or carefully specified as to where they are. So you'll need to give more specific information about what you have, and what you want to do. "Rename a file" has too many possibilities.
cmulgrum Posted February 14, 2007 Posted February 14, 2007 I've created the basic scripts in editor...but then went to add FM fields and calculate in FMP. But, I got slammed with "", """" and /" !! and errors because can't seem to find the proper conventions. The other thing missing from my (yours too LOL) solution is error trapping. If the user Cancels out of the Choose prompt, then I need to evaluate the return code in FM or in the Applescript or both? This is an interesting learning experience...thanks for your help! 1. User presses button to choose file (it's stored locally because he was working on it from scratch) OR (it is stored on the server, but not named properly. This is an image catalog being built from a mess of folders out on the server.) Script calculates old path, copies file to new location. New location is based on fields in the current layout including Root Folder (design name) and below that, design folder (based on style number, color, and shirt profile...it's a t-shirt) All of this is in the current layout. If the root folder doesn't exist, then create it. Calculate the name of the design folder and create it..if it doesn't exist. Now rename the old file and copy it to the design folder from it's old location. Based on this logic...Old location can be anywhere.
cmulgrum Posted February 14, 2007 Posted February 14, 2007 Fenton, after discovering Troi, no need to continue...their file plug-in covers everything I need. Thanks again for all of your input.
Recommended Posts
This topic is 6493 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