Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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
share|improve this question

1 Answer 1

up vote 1 down vote accepted

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
share|improve this answer
    
Thanks - that looks extremely promising! –  cormullion Aug 14 '12 at 8:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.