Skip to content

Instantly share code, notes, and snippets.

@0187773933
Created November 9, 2025 02:30
Show Gist options
  • Select an option

  • Save 0187773933/715d160f90c5715c0cc6e52607e967a5 to your computer and use it in GitHub Desktop.

Select an option

Save 0187773933/715d160f90c5715c0cc6e52607e967a5 to your computer and use it in GitHub Desktop.
osascript Apple Script to Batch Export PowerPoints to PDF
#!/bin/bash
# Usage:
# ./export.sh "/path/to/folder"
folder="$(cd "$1" && pwd)"
if [[ ! -d "$folder" ]]; then
echo "Usage: $0 /path/to/ppt/folder"
exit 1
fi
echo "📁 Using folder: $folder"
# Build AppleScript
osascript <<EOF
set inputFolder to POSIX file "$folder" as alias
tell application "Finder"
set pptFiles to (files of inputFolder whose name extension is "pptx")
if (count of pptFiles) = 0 then
display dialog "No PPTX files found" buttons {"OK"}
return
end if
end tell
tell application "Microsoft PowerPoint"
activate
end tell
repeat with f in pptFiles
set filePath to (f as alias)
tell application "Microsoft PowerPoint"
open filePath
activate
end tell
delay 3.0 -- allow PPT to fully load the file
tell application "System Events"
tell process "Microsoft PowerPoint"
set frontmost to true
delay 0.5
-- Open FILE menu (index 3 on your Mac)
click menu bar item 3 of menu bar 1
delay 0.4
-- Click Export… (item 10 in your File menu)
click menu item 10 of menu 1 of menu bar item 3 of menu bar 1
delay 1.5
-- Hit Export, then confirm with Enter
keystroke return
delay 0.4
keystroke return
end tell
end tell
delay 10 -- 🕐 wait for PDF to finish writing
tell application "Microsoft PowerPoint"
close active presentation saving no
end tell
delay 1.0
end repeat
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment