Skip to content

Instantly share code, notes, and snippets.

@BenHammersley
Created November 17, 2021 18:22
Show Gist options
  • Save BenHammersley/50988e6937e8b9bccad1321f117a70cd to your computer and use it in GitHub Desktop.
Save BenHammersley/50988e6937e8b9bccad1321f117a70cd to your computer and use it in GitHub Desktop.
Places the text of all the Keynote presentations in a specified directory into individual Markdown files and saves to a specified directory
--==============================
-- Places the text of all the Keynote
-- presentations in a specified directory into individual Markdown
-- files and saves to a specified directory
-- By Ben Hammersley
--
-- Based on
-- Send Keynote Text to Desktop Markdown File by: Richard Dooling https://github.com/RichardDooling/
--
-- Which was based on
-- Send Keynote Presenter Notes to Evernote by: Ben Waldie <ben@automatedworkflows.com>
--==============================
set this_folder to POSIX path of (choose folder with prompt "Pick the folder containing the files to process:") as string
set dest_folder to (choose folder with prompt "Pick the folder to place the resulting markdown:") as string
tell application "System Events"
set these_files to every file of folder this_folder
end tell
repeat with i from 1 to the count of these_files
try
set this_file to (item i of these_files as alias)
tell application "Keynote"
activate
open this_file
tell front document
-- Get the name of the presentation.
set thePresentationName to name
-- Retrieve the titles of all slides.
set theTitles to object text of default title item of every slide
-- If specified, retrieve the body text of all slides
set theBodyText to object text of default body item of every slide
end tell
close every document without saving
end tell
-- Prepare the notes as Markdown.
set theFormattedNotes to "# " & "Presentation: " & thePresentationName & "\n" & "\n"
repeat with a from 1 to length of theTitles
set theFormattedNotes to theFormattedNotes & "## Slide " & a & "\n" & "\n"
set theFormattedNotes to theFormattedNotes & "Title: " & item a of theTitles & "\n"
set theFormattedNotes to theFormattedNotes & "Body: " & "\n" & item a of theBodyText & "\n" & "\n"
end repeat
set theFormattedNotes to theFormattedNotes & return
-- Replace any returns with line breaks.
set AppleScript's text item delimiters to {return, ASCII character 10}
set theFormattedNotes to text items of theFormattedNotes
set AppleScript's text item delimiters to {return, ASCII character 10}
set theFormattedNotes to theFormattedNotes as string
set AppleScript's text item delimiters to "\n"
tell application "TextEdit"
activate
-- Create Desktop Markdown .md file named after Presentation
make new document with properties {text:theFormattedNotes}
save document 1 in file (dest_folder & thePresentationName & ".md")
close document 1
end tell
on error
log this_file as text
end try
end repeat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment