applescript not counting images in a Pages document

I'm trying to delete all the images in a Pages document using Applescript. The document was created by pasting an online chat transcript into a blank Pages document. I now want to strip out the avatars. I'm new to applescripting in Pages and have a simple script:


tell application "Pages"

activate

tell front document

get the count of images

end tell

end tell


which i thought should tell me how many images were in the document. It works with some other Pages documents, but not this one:

Dropbox - test.pages

(I've abbreviated the actual transcript!). Please can anyone tell me why the count is zero?


Apologies if this is the wrong Community.

MacBook Pro with Retina display, OS X El Capitan (10.11.6)

Posted on Jun 22, 2018 6:58 AM

Reply

Similar questions

3 replies

Jun 22, 2018 3:21 PM in response to jbh2

There is a Pages for Mac Support Community available to you.


The Pages v5/6/7 scripting dictionary limits you to finding local images that have been inserted into Pages from the toolbar media panel, or drag/dropped into it. These have local file names per the scripting dictionary image requirement.


Your AppleScript would work for local images. It will never work for images that have been copied and pasted from the web, as they have no filename. There is no AppleScript solution in Pages that I am aware that will identify non-local images with no name.

Jun 22, 2018 3:57 PM in response to VikingOSX

Thank you for that advice about the Pages images. Having changed the Pages filetype to a package and seen the *.png filenames of the images I naively thought that applescript would be able to work with them. You've saved me a lot of head scratching. And I turned to a much simpler solution for my original problem: I just select the entire contents of the document, and then Copy&Paste it into a blank rtf Textedit document. Job done.

Thanks too for the Pages for Mac support Community steer.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

applescript not counting images in a Pages document

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.