62°F

Aaron Parecki

  • Articles
  • Notes
  • Photos
  • How to create a keyboard shortcut to export the current slide in Keynote

    December 22, 2022

    Lately I've been using Apple Keynote to create graphics for using in videos and blog posts. It's a quick way to arrange things on a page, copying and pasting most things just works, and there are enough built in shapes and tools to get the point across. However, after spending a full day creating graphics for a video, I found myself frustrated by the number of clicks required to export a single slide at a time.

    I posted a quick note about this, and immediately got a lot of helpful replies! A lot of people suggested it should be possible to automate with KeyboardMaestro, a tool I was not previously familiar with. It was also suggested that I ask on the KeyboardMaestro forums, so I did, and also quickly received a very detailed reply!

    In the course of reading through these replies, I realized that the thing they all had in common was AppleScript! One reply in particular from Chris contained a pretty detailed AppleScript that appears to have been adapted from the iworkautomation website. So I took that as a starting point and wanted to see how I could make it work without also using KeyboardMaestro.

    Create a Quick Action in Automator

    First, open Automator and create a new Quick Action.

    new quick action

    In the new action that is created, set the "Workflow receives" option to no input, and choose Keynote.app in the application list.

    workflow settings

    Then search for the AppleScript action and drag it into the empty grey area.

    add applescript action

    Next, replace the (* Your script goes here *) text with the following AppleScript.

    AppleScript to export the current slide as a PNG in Keynote

    set the defaultDestinationFolder to (path to downloads folder)
    
    tell application "Keynote"
        activate
        try
            set currentSlideNumber to the slide number of (get the current slide of the front document)
    
            --- skip all but the current slide
            tell the front document
                set skipped of ¬
                    (every slide where the slide number is not equal to currentSlideNumber) to true
            end tell
    
            --- capture the document name
            set documentName to the name of the front document
            if documentName ends with ".key" then ¬
                set documentName to text 1 thru -5 of documentName
    
            --- create an empty folder to temporarily store the image
            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
    
            --- tell Keynote to export the current slide
            export the front document as slide images to file targetFolderHFSPath with properties ¬
                {image format:PNG, skipped slides:false}
    
            --- set all the slides back to unskipped
            tell the front document
                set skipped of every slide to false
            end tell
    
            --- move the file to the destination folder and delete the temporary folder 
            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
    
    

    Setting up a keyboard shortcut

    In the Automator app, save this quick action with a name like ExportCurrentSlide. You can quit Automator now.

    Now open System Preferences, open the Keyboard options, and go to the Shortcuts tab, then click on Services. Your new action should appear at the bottom of the list.

    keyboard options

    Click on the "none" at the right side of the action and you can record a keyboard shortcut for the action. I used "Shift Command 9" for mine.

    Close this, and go to Keynote to test it out!

    Choose the slide you want to export and press your keyboard shortcut! You should see a quick sequence of hiding all the slides, un-hiding them, and then the Downloads folder should pop up with your file name including the Keynote file name and slide number!

    There you go! A pure AppleScript solution, no third party apps needed! I just finished setting this up this morning and I'm already so much happier exporting slides now!

    Portland, Oregon • 20°F
    Thu, Dec 22, 2022 11:59am -08:00 #keynote #tutorial #automation
    2 replies
    • Aaron Parecki aaronparecki.com
      I found an AppleScript solution! https://aaronparecki.com/2022/12/22/10/export-current-slide-keynote
      Sat, Dec 24, 2022 7:30am -08:00
    • Miraz micro.blog/Miraz

      @aaronpk Fantastic! I was just thinking about this again exactly moments before seeing this post. I should have thought of Applescript! Anyway, so glad you can now export with one 'click' instead of a dozen! Now I'll remove this intriguing challenge from my brain. 😆

      Thu, Dec 22, 2022 8:14pm +00:00
Posted in /articles using quill.p3k.io

Hi, I'm Aaron Parecki, Director of Identity Standards at Okta, and co-founder of IndieWebCamp. I maintain oauth.net, write and consult about OAuth, and participate in the OAuth Working Group at the IETF. I also help people learn about video production and livestreaming. (detailed bio)

I've been tracking my location since 2008 and I wrote 100 songs in 100 days. I've spoken at conferences around the world about owning your data, OAuth, quantified self, and explained why R is a vowel. Read more.

  • Director of Identity Standards at Okta
  • IndieWebCamp Founder
  • OAuth WG Editor
  • OpenID Board Member

  • 🎥 YouTube Tutorials and Reviews
  • 🏠 We're building a triplex!
  • ⭐️ Life Stack
  • ⚙️ Home Automation
  • All
  • Articles
  • Bookmarks
  • Notes
  • Photos
  • Replies
  • Reviews
  • Trips
  • Videos
  • Contact
© 1999-2025 by Aaron Parecki. Powered by p3k. This site supports Webmention.
Except where otherwise noted, text content on this site is licensed under a Creative Commons Attribution 3.0 License.
IndieWebCamp Microformats Webmention W3C HTML5 Creative Commons
WeChat ID
aaronpk_tv