Insert images into Pages document using AppleScript

applescriptpages

I'm trying to automate the construction of a document, and am looking for a way to insert images into a Pages document with AppleScript. For example:

tell application "Pages"
    make new document
    tell document 1
      tell body text    
        make new paragraph at end with data ¬
         "another paragraph" with properties {paragraph style:"Body"}

        make new image at end with properties ??? :(

      end tell
    end tell
end tell

Nothing I've tried so far works – "make new graphic", "make new image", "insert image data" and so on. I'm not ruling out the possibility that it's not possible at all (I've used AppleScript for long enough, so that wouldn't be a surprise) but it would be good if it could be persuaded to work.

Solution

@jackjr300 's solution works great. I finally went with this incantation:

set fname to "/Users/me/Desktop/picture.png"
set thisImage to POSIX path of fname
tell application "Pages"
    tell document 1
        tell body text
            make new paragraph at end with data "another paragraph" with properties {paragraph style:"Body"}
            make new image at after last paragraph with properties {image data:thisImage}
        end tell
    end tell
end tell

Best Answer

Here's an example that works.

set thisImage to choose file with prompt "Select an image"
tell application "Pages"
  tell (make new document)
      tell body text
          make new paragraph at end with data "another paragraph" with properties {paragraph style:"Body"}
          make new image at after last paragraph with properties {image data:thisImage}
      end tell
  end tell
end tell