Guide for creating and editing Keynote presentations using AppleScript via bash
This skill guides you on how to create and manipulate Keynote presentations on macOS using AppleScript.
Create a Keynote presentation when the user asks to:
macos_show(app: "keynote") if visual mode is enabledALWAYS use a SINGLE AppleScript to create the entire presentation. Do NOT run multiple separate scripts.
Why this matters:
osascript invocation may restart Keynote's scripting bridgeBad approach (causes crashes):
# Script 1: Create document
osascript -e 'tell application "Keynote" to make new document'
# Script 2: Add slide 1
osascript -e 'tell application "Keynote" to tell front document to make new slide'
# Script 3: Set title
osascript -e 'tell application "Keynote" to tell front document to ...'
# This will likely crash!
Good approach (stable):
osascript << 'EOF'
tell application "Keynote"
activate
delay 1 -- Wait for Keynote to fully launch
-- Do ALL operations in ONE script
set newDoc to make new document with properties {document theme:theme "White"}
delay 0.5 -- Brief pause after creating document
tell newDoc
-- All slides and content in one block
...
end tell
end tell
EOF
Required delays:
activate: delay 1 (let app fully launch)make new document: delay 0.5delay 0.3 (optional but recommended for many slides)osascript << 'EOF'
tell application "Keynote"
activate
set newDoc to make new document with properties {document theme:theme "White"}
return name of newDoc
end tell
EOF
Available themes: "White", "Black", "Gradient", "Classic", "Modern Type", "Showcase", "Photo Essay", "Bold", "Industrial", "Blueprint"
osascript << 'EOF'
tell application "Keynote"
tell front document
-- Add slide with specific layout
set newSlide to make new slide with properties {base slide:master slide "Title - Center"}
end tell
end tell
EOF
Common master slides (layouts):
"Title - Center" - Title and subtitle centered"Title - Top" - Title at top with content area"Title & Subtitle" - Classic title slide"Title & Bullets" - Title with bullet points"Title, Bullets & Photo" - Title, bullets, and image"Bullets" - Full slide bullet points"Photo" - Full slide image"Photo - Horizontal" - Landscape photo layout"Quote" - Quote layout"Blank" - Empty slideosascript << 'EOF'
tell application "Keynote"
tell front document
tell current slide
-- Set title
set object text of default title item to "Your Title Here"
-- Set body text (for slides with body placeholder)
set object text of default body item to "• Point 1
• Point 2
• Point 3"
end tell
end tell
end tell
EOF
osascript << 'EOF'
tell application "Keynote"
tell front document
tell current slide
set newText to make new text item with properties {object text:"Custom text here"}
set position of newText to {100, 200}
set width of newText to 400
set height of newText to 100
end tell
end tell
end tell
EOF
osascript << 'EOF'
tell application "Keynote"
tell front document
tell current slide
set imgFile to POSIX file "/path/to/image.jpg"
set newImage to make new image with properties {file:imgFile}
set position of newImage to {300, 200}
set width of newImage to 400
end tell
end tell
end tell
EOF
osascript << 'EOF'
tell application "Keynote"
tell front document
set current slide to slide 3
end tell
end tell
EOF
osascript -e 'tell application "Keynote" to count slides of front document'
osascript << 'EOF'
tell application "Keynote"
tell front document
set exportPath to POSIX file "/Users/username/Desktop/presentation.pdf"
export to exportPath as PDF
end tell
end tell
EOF
osascript << 'EOF'
tell application "Keynote"
tell front document
set savePath to POSIX file "/Users/username/Desktop/my_presentation.key"
save in savePath
end tell
end tell
EOF
This is the recommended pattern - ALL operations in ONE script with proper delays:
osascript << 'EOF'
tell application "Keynote"
activate
delay 1 -- IMPORTANT: Wait for Keynote to fully launch
-- Create new document
set newDoc to make new document with properties {document theme:theme "White"}
delay 0.5 -- Wait for document to initialize
tell newDoc
-- First slide is created automatically, set it as title slide
tell slide 1
set base slide to master slide "Title - Center"
set object text of default title item to "Q1 2026 Business Review"
set object text of default body item to "Financial Services Division"
end tell
delay 0.3
-- Add Overview slide
set slide2 to make new slide with properties {base slide:master slide "Title & Bullets"}
delay 0.3
tell slide2
set object text of default title item to "Executive Summary"
set object text of default body item to "• Revenue increased 15% YoY
• New client acquisition: $15M AUM
• Client satisfaction: 4.8/5.0
• All portfolios outperforming benchmarks"
end tell
-- Add Performance slide
set slide3 to make new slide with properties {base slide:master slide "Title & Bullets"}
delay 0.3
tell slide3
set object text of default title item to "Investment Performance"
set object text of default body item to "• Growth Portfolio: +3.2% (Benchmark +2.8%)
• Balanced Portfolio: +2.1% (Benchmark +1.9%)
• Income Portfolio: +0.9% (Benchmark +0.7%)
• Average Alpha: +0.3%"
end tell
-- Add Next Steps slide
set slide4 to make new slide with properties {base slide:master slide "Title & Bullets"}
delay 0.3
tell slide4
set object text of default title item to "Q2 Priorities"
set object text of default body item to "• Complete endowment fund implementation
• Expand alternative investment offerings
• Launch client education seminar series
• Target: $25M total new AUM"
end tell
delay 0.5 -- Wait before saving
-- Save the presentation
set savePath to POSIX file "~/Desktop/Q1_Review.key"
save in savePath
end tell
return "Presentation created with 4 slides"
end tell
EOF
Key points about this example:
osascript command containing everythingdelay 1 after activate to let Keynote fully launchdelay 0.5 after creating documentdelay 0.3 after each make new slidedelay 0.5 before save operationWhen Keynote operations fail, common issues are:
macos_show(app: "keynote") first, then wait 1-2 seconds before running the creation script./Users/username/Desktop/)delay statements, especially after make new slideIf the script times out or crashes:
delay 1 instead of delay 0.3)IMPORTANT: Always close Keynote after you finish creating and saving the presentation.
If you have macos_close tool available (Visual Demo Mode), use:
macos_close(target: "keynote", delay_ms: 500)
Alternatively, use AppleScript:
osascript -e 'tell application "Keynote" to quit'
This keeps the user's desktop clean and shows a complete workflow.
~/Desktop/ or user's preferred locationQ1_2026_Review.key and Q1_2026_Review.pdf)