Keynote: Automate Media Placeholder image replacement from folder
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

Hi there,

I’m looking for a solution to automate the rather tedious task of replacing a mass of image placeholders in Keynote with images from a selected folder.

I’ve built a Template Slide Layout with Media Placeholders arranged in my desired grid. I’d like to have a script that, when run, will replace each of the placeholders with an image from a selected folder, in sequential order.

Another tricky detail, and this is very important, is that I need it to populate additional pages if the selected folder has more images in it than can fit on one page. For example, my template has 45 Media Placeholders on one page; so if my folder has 122 images in it, the script would need to populate 3 pages. It would be okay if a manual task at the end would be to delete the remaining placeholders that were not populated.

I found an example script that will replace a single Media Placeholder (pasted below). But I’m not savvy enough in writing code to expand on this for my purposes.

I’m open to whatever scripting language works. Building it in AppleScript or Javascript, or whatever else is compatible with MacOS and Keynote should be fine.

Here is a Keynote presentation and folder of placeholder images for testing:
https://www.dropbox.com/sh/m8gjjg4ejtm0ol5/AADftNGNG4WwvQ_P4CJysydLa?dl=0

Thanks!


tell application "Keynote"
activate
tell the front document
tell the current slide

        -- TO REPLACE A PLACEHOLDER OR EXISTING IMAGE:
        -- change the value of the file name property of the image to be an HFS file reference to the replacement image file
        set thisPlaceholderImageItem to image 1
        set file name of thisPlaceholderImageItem to ¬
            alias "Macintosh HD:Users:sal:Pictures:Saturn.jpg"

    end tell
end tell

end tell

awarded to radosinsky

Crowdsource coding tasks.

1 Solution

Winning solution

Hello,
here's my AppleScript solution to this: https://gist.github.com/radosinsky/a2faf98fd207c2527895983899402c30

The script will:

  1. Duplicate first slide based on the file count

  2. Go through all the placeholders and replace them with images (starting from image_00001.jpg)

  3. Remove any extra placeholders from the last slide

Let me know if this solves your problem or if you have any questions, thank you!

Thanks radosinsky! What a great solution. Cheers!
techweather 3 months ago