Auto Convert a Keynote to PDF and PowerPoint

Hello all. I finally realized the usefulness of Hazel and have been wondering if there is a way to automate converting a Keynote presentation into a PDF and PowerPoint.

A bit of AppleScript should be able to do this. There are a couple of helper and two main handlers - one for each export. I’ve blocked them all together here but you could have two different scripts. You can also parameterise (specifying which export option) to have just one main handler that allows for both, but I figured you could do that amendment yourself if you were interested in consolidating it a bit.

-- Get folder path of file
on getFolderPath(p_strFullPath)
	do shell script "dirname " & quoted form of p_strFullPath
end getFolderPath

-- Get basename of file with no file extension, independent of default shell
on getBaseName(p_strFullPath)
	do shell script "basename " & quoted form of p_strFullPath & " | sed -E 's/\\.[^.]*$//'"
end getBaseName

-- Export to PDF in same folder with same file name
on exportPDF(p_strFullPath)
	set strOutputFilePath to getFolderPath(p_strFullPath) & "/" & getBaseName(p_strFullPath) & ".pdf"
	tell application "Keynote"
		set objKeynoteFile to open (p_strFullPath as POSIX file)
		export objKeynoteFile to (strOutputFilePath as POSIX file) as PDF
		close objKeynoteFile saving no
	end tell
end exportPDF

-- Export to PowerPoint in same folder with same file name
on exportPowerPoint(p_strFullPath)
	set strOutputFilePath to getFolderPath(p_strFullPath) & "/" & getBaseName(p_strFullPath) & ".pptx"
	tell application "Keynote"
		set objKeynoteFile to open (p_strFullPath as POSIX file)
		export objKeynoteFile to (strOutputFilePath as POSIX file) as Microsoft PowerPoint
		close objKeynoteFile saving no
	end tell
end exportPowerPoint

-- Examples
exportPDF("/Users/stephen/Documents/Keynotes/Example 1.key")
exportPowerPoint("/Users/stephen/Documents/Keynotes/Example 1.key")

Just take the examples and code and hook that into your Hazel setup however you like. Add scripts and call from the command line (e.g. via osascript), call an Apple Shortcuts shortcut and embed the AppleScript in that, etc.

Thanks. I’ve added some tweaks and support for multiple file drops on the script’s icon. Code is here: