Search code examples
javascriptkeynote

Running Macro or Javascript in Keynote?


Our church uses Keynote for putting songs on the projector, along with other things.

At the end of service, we have a countdown timer for when classes will start.

I've been wanting to add text showing when classes will end, but as it can change each week due to length of services, it can't be static.

Is there any way to embed something like JS in Keynote so it could take the current time, add 45 minutes to it, and then display the resulting time as text?


Solution

  • You should be able to do this with this library (there may be others around too). The repo has some usage examples for various things.

    Some basic examples:

    // This one should allow to use existing documents in JS.
    const result = await document.getSelectedDocument();
    console.log(result);
    
    const doc = new Document({ name: 'Test 123', theme: 'Test Theme' });
    const docSlides = await doc.getSlides();
    
    docSlides[0].setTitle('Welcome to Slide 1!', { fontSize: 90 });
    

    You can easily add a date to this title string and format it to your liking. How to add some amount of minutes to a date is addressed in this SO question.

    It doesn't mention any additional setup, beyond running it with NodeJS (node my-script.js). The application detects the currently active Keynote window by itself.

    Perhaps it needs some kind of OS permission, but I can't test it as I'm currently not on an Apple device.

    You can just copy and adapt their example scripts as a starting point, and you should be able to get it working.