Skip to content

Instantly share code, notes, and snippets.

@chris-79
Last active January 4, 2023 16:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-79/4ffb9318c42cb3d0a0e8e7d670cfd332 to your computer and use it in GitHub Desktop.
Save chris-79/4ffb9318c42cb3d0a0e8e7d670cfd332 to your computer and use it in GitHub Desktop.
property includeSkippedSlides : false
set the defaultDestinationFolder to (path to downloads folder)
tell application "Keynote"
activate
try
if playing is true then tell the front document to stop
if not (exists document 1) then error number -128
set currentSlideNumber to the slide number of (get the current slide of the front document)
tell the front document
set skipped of ¬
(every slide where the slide number is not equal to currentSlideNumber) to true
end tell
set documentName to the name of the front document
if documentName ends with ".key" then ¬
set documentName to text 1 thru -5 of documentName
tell application "Finder"
set newFolderName to documentName & " slide " & currentSlideNumber
set incrementIndex to 1
repeat until not (exists folder newFolderName of defaultDestinationFolder)
set newFolderName to documentName & "-" & (incrementIndex as string)
set incrementIndex to incrementIndex + 1
end repeat
set the targetFolder to ¬
make new folder at defaultDestinationFolder with properties ¬
{name:newFolderName}
set the targetFolderHFSPath to targetFolder as string
end tell
export the front document as slide images to file targetFolderHFSPath with properties ¬
{image format:PNG, skipped slides:includeSkippedSlides}
tell the front document
set skipped of every slide to false
end tell
tell application "Finder"
set folderContents to every item of targetFolder
repeat with theFile in folderContents
set fileExtension to name extension of theFile
set fileName to the name of theFile as string
set splitCharacters to ".001"
set ATID to AppleScript's text item delimiters
set AppleScript's text item delimiters to splitCharacters
set newFileName to text item 1 of fileName
set AppleScript's text item delimiters to ATID
set newFileName to newFileName & "." & fileExtension
set name of theFile to newFileName
-- display dialog quoted form of (name of theFile as string)
end repeat
move files of entire contents of targetFolder to defaultDestinationFolder with replacing
delete targetFolder
-- open the destination folder
tell application "Finder"
set thePath to file (defaultDestinationFolder & newFileName as string)
activate
reveal the thePath
end tell
end tell
on error errorMessage number errorNumber
display alert "EXPORT PROBLEM" message errorMessage
error number -128
end try
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment