Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@radosinsky
Created July 29, 2021 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radosinsky/a2faf98fd207c2527895983899402c30 to your computer and use it in GitHub Desktop.
Save radosinsky/a2faf98fd207c2527895983899402c30 to your computer and use it in GitHub Desktop.
tell application "Finder"
set imagesFolder to "/Users/username/Downloads/keynote_image-grid_scripting/images"
set filesCount to number of files in folder (POSIX file imagesFolder as alias)
end tell
tell application "Keynote"
activate
tell the front document
set imagesReplaced to 0
set imagesPerSlide to the count of images of slide 1
set slidesCount to round filesCount / imagesPerSlide rounding up
repeat slidesCount - the (count of slides) times
duplicate slide 1
end repeat
repeat with i from 1 to the count of slides
tell slide i
repeat with j from 1 to the count of images
set imageNumber to text -5 thru -1 of ("00000" & j + imagesReplaced)
set imagePath to imagesFolder & "/image_" & imageNumber & ".jpg"
try
set file name of image j to POSIX file imagePath as alias
on error
exit repeat
end try
end repeat
set imagesReplaced to imagesReplaced + the (count of images)
end tell
delete (every image of slide i where the file name is "placeholder.jpg")
end repeat
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment