The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniGraffle > OmniGraffle General
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Applescripting Import and Export -> PNG to EPS Thread Tools Search this Thread Display Modes
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 - Export thread - 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
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. See SteveF's script 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
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.
We're working on a better fix for the future, in the meantime this does work as a workaround.
__________________
"Vroom! Vroom!!"
 
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 - http://www.apple.com/applescript/imageevents/ - 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
Thanks again! I hope this helps!

Cheers, Ian
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best way to export and import to and from Onenote dwbrown77 OmniOutliner 3 for Mac 0 2012-12-26 04:46 AM
OO iPad - Sync vs Import/Export? [A: Import/Export; mail ninjas to request sync.] countdrachma OmniOutliner for iPad 6 2011-05-10 11:58 PM
Database export import not possible jochen OmniFocus 1 for Mac 2 2009-07-23 08:29 AM
SVG export/dot import Vincent22 OmniGraffle General 2 2007-01-10 03:24 PM


All times are GMT -8. The time now is 03:46 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.