Newbies conversionlog Posted February 2, 2013 Newbies Posted February 2, 2013 I've been lurking on this forum for weeks building scripts into this database, but I'm finally no-kidding-stuck and need some help! We have a layout that shows 100px images for reference purposes, but users are dragging giant images into them. I'm trying to create a script that will take an image in a field, resize it to 100px and replace the original. The result would be that the field now has a 100px version of what it used to have. I wrote an AppleScript to run when the field has new content in it, but I can't get it to work. tell application "System Events" keystroke "c" using {command down} end tell tell application "Image Events" set currentImage to the clipboard scale currentImage to size 100 tell application "Finder" to set newImage to (container of anImage as string) & "sm_" & (name of anImage) & ".jpg" save currentImage in newImage as JPEG with compression level low set clipData to read file newImage as JPEG picture set the clipboard to clipData end tell tell application "System Events" keystroke "p" using {command down} end tell set the clipboard to "" In my head, the logic looks like this: Copy what's in the field to the clipboard. Tell the finder to make the small version. Copy the small version to the clipboard. Paste the small version back into the database. Clear the clipboard. My hangup right now is Filemaker doesn't even seem to be doing the keystroke "c" to copy the image in the first place. This all seems like such a backwards way of doing things that I'm open to suggestion in a broad sense as well.
Opotoc Posted February 2, 2013 Posted February 2, 2013 Hi, actually the idea to get the data from the clipboard is inspiring... I think if this could work (no idea) you would need to tell the AppleScript to select the field in FileMaker containing the image first. Better write the image to disk, do the resizing and re-add it to your container. You code looks good, in case somethings still not working, the below is working fine for me and does the same. // FileMaker Script calcualtion! // $fileS = the POSIX path of the image inside the FileMaker temp folder for example "tell application "Image Events"¶ launch¶ set the target_width to 100¶ -- open the image file¶ set this_image to open "" & $fileS & ""¶ ¶ set typ to this_image's file type¶ ¶ copy dimensions of this_image to {current_width, current_height}¶ if current_width is greater than current_height then¶ scale this_image to size target_width¶ else¶ -- figure out new height¶ -- y2 = (y1 * x2) / x1¶ set the new_height to (current_height * target_width) / current_width¶ scale this_image to size new_height¶ end if¶ ¶ tell application "Finder"¶ save this_image¶ end tell¶ end tell" Best, Alexander
Newbies ChristianaDIOM Posted February 27, 2013 Newbies Posted February 27, 2013 These code looks a little difficult, why not take some online image processing sdk including recizing as a template...
Recommended Posts
This topic is 4290 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