Inserting an image into a Pages document

The image class in Pages has no file parameter. It has an image data parameter, which I presume you set to contain the image pixels. But this is an image binary data type which is a class that cannot be made.

So how do I supply an image file to this image class?

Without an image, the default ink bottle and pen image always appears.


Model: iMac
AppleScript: 2.1.2
Browser: Firefox 3.6.8
Operating System: Mac OS X (10.6)

Hi, MoffyUK. Welcome to MacScripter.

I’ve not succeeded in setting an image directly in a Pages document, but pasting’s possible, if it’s any help:

set pic to (read (choose file of type "JPEG") as "JPEG") -- Change this line if reading a different sort of image file!
set the clipboard to pic

tell application "Pages"
	set body text of front document to "Here is a picture: Hopefully, it's above this sentence!"
	select insertion point after character 19 of body text of front document
end tell

tell application "System Events" to keystroke "v" using command down

I’m finding that the ‘set the clipboard to’ command sometimes freezes in this script when I run it in AppleScript Editor, which I then have to force quit. But it seems OK when run from the Script Menu ” so far.

Many thanks for your reply.

I am new to the iMac as much as to this forum, but it seems that there are many roadblocks to script writing such as this. It is all well and good for Apple to inform in the Pages dictionary that an image binary cannot be ‘made’, but without a working alternative, they are fundamentally failing their audience. After decades in IT, the matter of documentation is still one that is addressed with too little regard for its use.

If this sounds like I am complaining without wanting to carry out work arounds, I did just that when I was learning Delphi in 2002 - I wrote as I learnt the language in lieu of usable documentation from Borland at the time. Or since.

With applescript, intuition seems rarely to help.

Is there a way to find out from Apple how to insert an image? Doing so via paste bypasses the programmatic interface that the dictionary is supposed to supply, and hardly sets up confidence in using script on an ongoing basis. Apple would surely benefit from an improved dictionary.

Many thanks

The dictionary doesn’t describe a way to insert a picture because the feature is unavailable in the code linking AppleScript and the application.

Using GUIscripting carefully, we may make a lot of interesting things.

Yvan KOENIG (VALLAURIS, France) vendredi 27 août 2010 15:48:19

Many thanks. Understood, but it is not easy in isolation to determine that this is indeed the case. There is the implication that you cannot insert an image, but it is not stated explicitly. I was able to insert an image place-holder successfully, so support is half there.

Hi Nigel Garvey,

your tip how to copy an image to the Clipboard didn’t work in my hands.

set pic to (read (choose file of type "JPEG") as "JPEG") -- Change this line if reading a different sort of image file!
set the clipboard to pic

The clipboard remains empty.

But I found this older hint ( that works nicely:

   set the clipboard to (read (choose file with prompt "Select an image file:" without invisibles) as TIFF picture)
end try