Apple-scripting "Place Image..." ?

Greg Titus greg at omnigroup.com
Mon Jul 14 09:37:01 PDT 2003


On Thursday, July 10, 2003, at 06:55  PM, A. James Boswell wrote:

> Hi all,
> there doesn't seem to be any way to applescript the "File->Place 
> image...", or dragging an image file to a canvas behaviour. I don't 
> really want to use GUI scripting because I want this long script 
> (assembling image fragments at co-ordinates) to run in the background 
> while I do my work - not constantly activate and switch to the front.
>
> Any ideas? Are there any apple events that are not in the dictionary 
> that I can use? Or is this feature planned soon?

You are looking for the "image" property on the "solid" class. A script 
like this should do what you want:

tell application "OmniGraffle Professional"
	tell page of front window
		make new shape at end of graphics with properties {origin:{0, 0}, 
size:{100, 100}, draws stroke:false, draws shadow:false}
		set image of result to "/Users/toon/Pictures/Grassy.jpg"
	end tell
end tell

Note that this isn't an exact analogue of the "Place Image..." behavior 
because it sets the image fill of an existing shape instead of creating 
a new shape for that image. The difference is, you'll need some other 
way of determining the image's natural size, since that isn't exposed 
to AppleScript in OmniGraffle.

Here is a script which _is_ an exact analogue of "Place Image...", 
using Standard Scripting Additions to open up a panel to ask you for an 
image file, then using Image Capture Scripting to determine the image 
size, then creating the shape and setting its image fill in OmniGraffle:

set theFile to choose file with prompt "Image to place:"
tell application "Image Capture Scripting"
	set theImage to open theFile
	set theSize to {width of theImage, height of theImage}
	close theImage
end tell
tell application "OmniGraffle Professional"
	tell page of front window
		make new shape at end of graphics with properties {origin:{0, 0}, 
size:theSize, draws stroke:false, draws shadow:false}
		set image of result to POSIX path of theFile
	end tell
end tell

Hope this helps,
	- Greg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 6147 bytes
Desc: not available
Url : /mailman/archive/omnigraffle-users/attachments/20030714/bd9be0ad/attachment.bin


More information about the OmniGraffle-Users mailing list