Applescripting Import and Export -> PNG to EPS
Hello all,
OG Version: OmniGraffle 4.2.3 I am not a fluent applescripter - so please bear with me if there are obvious solutions to these problems: I've tested the export scripts on the various threads on this forum - [URL="http://forums.omnigroup.com/showthread.php?t=106"]Export thread[/URL] - but commonly receive errors when exporting to EPS. I wish to make a droplet that will process dopped PNG screenshots (with transparency) to EPS (with transparency), maybe saving the graffle document along the way. One graphic per canvas. Here's a simple import PNG/other-graphics-format script (currently not working!) [CODE]-- This droplet processes files dropped onto the applet on open these_items tell application "Finder" set saveFolder to desktop as string end tell try process_item(these_items) end try end open -- this sub-routine processes files on process_item(this_item) tell application "OmniGraffle Professional 4" activate open document tell canvas 1 activate import (this_item) end tell end tell end process_item[/CODE] I see the IMPORT dictionary docs have numerous parameters - I would love a simple example showing how this works. Here's my current export script (greatly simplified from the other examples). I will tie them together when I get my head around the basic simple functionality. Even when testing the working export scripts e.g. [URL="http://forums.omnigroup.com/showthread.php?t=106"]See SteveF's script[/URL] and changing PNG export to EPS, the scripts fails with: OmniGraffle Professional 4 got an error: The document cannot be saved in the "eps" format. Are there additional export settings I need to set to export to EPS: Here's a simple (non working example): [CODE]tell application "OmniGraffle Professional 4" set myWindow to front window set myDoc to document of myWindow set export_folder to (choose folder with prompt "Pick the destination folder") as string set exportType to "EPS" set exportFileExtension to "eps" set exportFileName to export_folder & "myFile" & "." & exportFileExtension set include border of current export settings to false set copy linked images of current export settings to false set area type of current export settings to selected graphics set draws background of current export settings to false --set export scale to "100.0" -- not sure of what a 'real' is applescript - a decimal? tell front document activate save myDoc as exportType in exportFileName end tell end tell[/CODE] Any help, simple examples will be gratefully received. Regards, Ian Grant |
This is due to a change in Leopard, we've found out that the 'as "foo"' parameter doesn't work, however a UTI or CFBundle TypeName will. Quoth the OmniGraffle Team Lead:
[QUOTE]After some investigation I think the problem is that Apple changed the interpretation of the "as foo" parameter in 10.5. The new behavior requires either a UTI or a CFBundleTypeName (it uses the new NSWorkspace type:conformsToType: method to search for a matching type in the list returned by -writableTypesForSaveOperation:; the method expects UTIs but is documented to take "other type names, including those declared in CFBundleTypeName Info.plist entries", which is a good thing because the strings that -writableTypesForSaveOperation: returns are not UTIs. It's not clear what other ways of specifying types might be accepted also.) Right now it works if you specify a CFBundleTypeName string. From the release notes it looks like we can make it accept UTIs as well. The CFBundleTypeName strings in Graffle at the moment are: "OmniGraffle Format", "Apple PDF pasteboard type", "NeXT TIFF v4.0 pasteboard type", "PNG", "JPEG Format", "EPS Format", "HTML Image Map", "HTML Directory", "OOOutlineDocumentType", "Scalable Vector Graphics XML File Type", "PICT", "Photoshop", "BMP", and "VisioXMLDrawingType". The other workaround is to leave off the "as foo" entirely; AppKit will guess a format from the file extension.[/QUOTE] We're working on a better fix for the future, in the meantime this does work as a workaround. |
Some success at importing images and exporting EPS
Hi, thanks for the advice Joel,
I am now getting my head around applescript and interpreting application's applescript dictionaries! After a bit of applescript research and taking apart the address book chart example, I think I nearly have what I need. There may be an easier or neater way but this works - I noticed the address book example creates a shape then sets an image as a fill and this is the way to 'import' an image rather than use the 'import' command. I use the 'image events' features - [URL="http://www.apple.com/applescript/imageevents/"]http://www.apple.com/applescript/imageevents/[/URL] - to get the size of the incoming image, and resize the shape. One ongoing issue - I can't seem to solve: both the applescript export settings and the omnigraffle export settings for EPS when set to 'transparent background' do not export a transparent background. More accurately, if the imported graphics (a PNG) contains transparency, it is flattened (to white). If I draw a circle overlapping the edge in OG, then export to EPS, the canvas (outside of any shadowed area) is transparent. Maybe this is working as expected. I think I wont apply the drop shadow in the screen-capture application and add it during the automated process... I post the full applescript code should this help anyone wondering how you can place a graphic in omnigraffle 4.2.3 using applescript and how the export business works. [CODE] -- convert image to EPS and GRAFFLE document applescript droplet -- assembled by Ian Grant 2008 -- tested with OmniGraffle 4.2.3 and Mac OS 10.5.3 -- currently the script wont repeat over multiple dropped files global myDocument -- Some configurable Settings property templateName : "A4 with Grid (Metric)" -- Graffle template to use when creating a document - make sure you have it! property exportFileType : "EPS" -- current workround use FILE extension to save as supported export types property exportFileExtension : "eps" property myScale : "1.0" -- 1.0 = full size property myResolution : "1.0" -- The number of pixels per point in the resulting exported image (1.0 for 72 DPI). property shouldClose : "true" property defaultName : "myEPSImage" -- End of Configurable Settings -- droplet routine on open of target_files -- TODO Sanity Check - check all dropped files are images try tell application "OmniGraffle Professional 4" --activate set myDocument to (make new document at end of documents) set template of myDocument to templateName set myCanvas to canvas 1 of myDocument set originShape to my makeShape(myCanvas, target_files) end tell end try -- call the export and save as graffle routine my exportImageAsGraffleAndEPS(target_files) end open -- make the shape - I can't get the import construct to work - so I make a shape and set its fill with the image. on makeShape(onCanvas, myFile) using terms from application "OmniGraffle Professional 4" tell onCanvas set theShape to make new shape at front of graphics with properties {origin:{0, 0}, thickness:0.0, fill:no fill, draws stroke:false, image scale:1, size:{20, 20}, draws shadow:false} my getPicture(theShape, myFile) return theShape end tell end using terms from -- OmniGraffle end makeShape -- Get the dropped image, get it's size and set it as a fill to the shape, and some (adjustable) settings. on getPicture(theShape, myFile) set filePath to (myFile) as string set posixPath to POSIX path of file filePath try tell application "Image Events" -- start the Image Events application launch -- open the image file set this_image to open filePath -- extract the property value set the props_rec to the properties of this_image copy (dimensions of props_rec) to {myX, myY} -- purge the open image data close this_image end tell end try tell application "OmniGraffle Professional 4" ignoring application responses set image of theShape to posixPath set image sizing of theShape to manual set image scale of theShape to 1 set image offset of theShape to {0, 0} set size of theShape to {myX, myY} select theShape end ignoring end tell end getPicture -- export EPS and GRAFFLE on exportImageAsGraffleAndEPS(filename) tell application "OmniGraffle Professional 4" set myWindow to front window set myDoc to document of myWindow --prompt for save destination set export_folder to (choose folder with prompt "Pick the destination folder") as string --prompt for file name set myFileName to text returned of (display dialog "Enter new filename (no extension required)" buttons {"OK"} default button 1 default answer defaultName with icon 2) set exportFileName to export_folder & myFileName & "." & exportFileExtension set asSourceFileName to export_folder & myFileName & "." & "graffle" -- SANITY CHECK if chosen filename already exists -- TODO check validy of file name repeat tell application "Finder" activate if exists file asSourceFileName then --asSourceFileName Already exists set myFileName to text returned of (display dialog "File already exists. Enter new filename." buttons {"OK"} default button 1 default answer defaultName with icon 2) set exportFileName to export_folder & myFileName & "." & exportFileExtension set asSourceFileName to export_folder & myFileName & "." & "graffle" else if exists file exportFileName then --exportFileName Already exists set myFileName to text returned of (display dialog "File already exists. Enter new filename." buttons {"OK"} default button 1 default answer defaultName with icon 2) set exportFileName to export_folder & myFileName & "." & exportFileExtension set asSourceFileName to export_folder & myFileName & "." & "graffle" else exit repeat end if end tell end repeat set exportType to exportFileType set exportFileExtension to exportFileExtension set exportFileName to export_folder & myFileName & "." & exportFileExtension set asSourceFileName to export_folder & myFileName & "." & "graffle" -- export settings TODO make more of them configurable? set include border of current export settings to false set area type of current export settings to selected graphics set draws background of current export settings to false set export scale of current export settings to myScale set resolution of current export settings to myResolution -- do the export and save tell front document activate -- save export save myDoc in exportFileName -- safe graffle save myDoc in asSourceFileName -- close doc if configure to if shouldClose is "true" then close end tell end tell end exportImageAsGraffleAndEPS [/CODE] Thanks again! I hope this helps! Cheers, Ian |
All times are GMT -8. The time now is 02:36 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.