Building a Clock Overlay For Your iMovie Videos

If you need a clock or countdown timer in your iMovie video, you can create one in Keynote and export it to use in iMovie. You can manually create each second as a slide, or use this simple script to add all of the slides automatically. In iMovie you can adjust the size, color and even reverse the overlay to count down or up.



Here’s the script. Remember when in Script Editor to switch from AppleScript to JavaScript.

var Keynote = Application("Keynote");
var presentation = Keynote.documents[0];
var slideMaster = presentation.masterSlides["Statement"];

for(var i=0;i<=120;i++) {
	var m = Math.floor(i/60);
	var s = i-m*60;
	var newSlide = Keynote.Slide({baseSlide:slideMaster});
    presentation.slides.push(newSlide);
    newSlide.defaultBodyItem().objectText = m+":"+String(s).padStart(2, '0');
}

Comments: 39 Responses to “Building a Clock Overlay For Your iMovie Videos”

    Jack
    4 years ago

    Hi Gary, thanks for this VERY helpful post. Can the script be edited to automatically create slides counting down (as opposed to yours that is counting up)? I know you showed how iMovie can reverse the video, but I would like to use the exported timer movie in Keynote alongside of an interactive scoreboard for games. I'm just trying to avoid having to bring the movie file into iMove, reverse the video, export a new video, and then bring it back into Keynote. Thanks!

    4 years ago

    Jack: You can just change the for loop. It counts from 0 to 120 now, so make it count from 120 to 0, like:

    for(var i=1200;i>=0;i--)
    Jack McNeil
    4 years ago

    Thanks for your help Gary. When I put that line of code in, I get the following error:

    Error on line 5: SyntaxError: Unexpected token ')'

    4 years ago

    Jack: Make sure you get it exactly, Note that it is two minus characters at the end to replace the two plus characters from the original.

    Jack McNeil
    4 years ago

    That did it! Thank you very much.

    Carol Brunger
    4 years ago

    Gary, thank you so much for this video. It is so well explained, and the bonus being able to copy and past the script, was a godsend. Once again forever grateful for your videos.

    Law Thim Fook
    4 years ago

    TQVM Gary, for another great and enlightening video.

    sumaia
    4 years ago

    Thank you so much for the amazing video. I am just wondering what I should change in the coding script to make the video a countdown of 50 minutes?

    Thank you once again,
    Sumaia

    4 years ago

    sumaia: 50 minutes is 60 times 50 seconds. So 3000 seconds. So change the 120 in the code to 3000. It will take a while to create, but it should still work.

    sumaia
    4 years ago

    var Keynote = Application("Keynote");
    var presentation = Keynote.documents[0];
    var slideMaster = presentation.masterSlides["Title - center"];

    for(var i=3000;i>=0;i--) {
    var m = Math.floor(i/60);
    var s = i-m*60;
    var newSlide = Keynote.Slide({baseSlide:slideMaster});
    presentation.slides.push(newSlide);
    newSlide.defaultBodyItem().objectText = m+":"+String(s).padStart(2, '0');
    }

    this is what i have but numbers are for not showing. Also, I used title-center instead of Statement.

    sumaia
    4 years ago

    I actually got it ! THANK YOU SO MUCH. literally your video was the only helpful video i found!!

    Isaac
    4 years ago

    Hi, Gary, I have Keynote 10.2 version in Spanish Language but your script doesn't work in my Mac computer and I received this message: Error: TypeError: undefined is not an object (evaluating 'presentation.masterSlides')

    4 years ago

    Isaac: Just try going through everything step-by-step and setting it up the same way I do.

    Marie Gielens
    4 years ago

    Hi Gary, is there a way to add a voice or sound to the last seconds of the timer?

    4 years ago

    Marie: I would just record that yourself as an audio VoiceOver.

    Kiley
    4 years ago

    This was so INCREDIBLY HELPFUL. Thank you for the simple, easy to follow instructions.

    Alyssa
    4 years ago

    Hello Gary, I keep getting his error message "Error -1728: Can't get object." I have copied the code exactly, yet when I try to input it into keynote, it gives me that message.

    4 years ago

    Alyssa: That error suggests that maybe your open Keynote document isn't set up the same as what I am showing in the tutorial.

    Andrew
    4 years ago

    If you get “Error -1728: Can’t get object.”, write name of masterSlide like it named in your localisation.
    For example, in Russian version it named "Информационное сообщение".

    4 years ago

    Andrew: Not sure. Sounds like an issue with the language settings and just getting everything to match right.

    CHristian Cespedes
    4 years ago

    Hi Gary, the script is working creating the slides but not writing in the slide the result. How can i solve that?

    4 years ago

    Christian: Perhaps an issue with the template's text boxes? Try another template.

    Risjad
    4 years ago

    Hi Gary, the coding was succeed until automatically creating the slides. But the time is not showing. How can I solve this?

    4 years ago

    Risjad: Impossible for me to tell what could be wrong with how you did it. Try again following every step carefully.

    Joss
    4 years ago

    Hi Gary, thanks for this javascript - is there something different in Keynote on Big Sur (which I am running)?
    The script gives me an Error -2700 TypeError: the undefined is not an object (evaluating 'presentation.masterSlides') - note that the ' are in the message and not in the script.
    The script compiles just fine otherwise.
    Any thoughts?

    4 years ago

    Joss: No, it will work in Big Sur. Be sure your Keynote document looks like mine.

    Joss
    4 years ago

    Thanks, Gary, After some tweaking around, I managed to get the Javascript to work. Not sure what I did that was different - but it could have been spinning around in my chair first did the trick. Great script! Thanks1

    Jenny
    4 years ago

    Hi Garry I got Error- 1700: Can't convert types?

    4 years ago

    Jenny: Make sure your script and the Keynote presentation are exactly like I have them.

    Dorte
    4 years ago

    Thanks - This was just what I needed :-) It's working perfectly...

    James
    4 years ago

    For 10mins... would it be this? (var I=600;i>=0;i--)
    Thanks In advance!

    4 years ago

    James: yes. Lowercase i, of course. then a -- (two dashes) at the end.

    Jose Jimenez
    4 years ago

    Good afternoon Gary, I understand the java script you use. My question is I want it to go in reverse meaning not counting 0 -2;00 but 2:00 - 0 do you make any change to the script in order for that order to work?

    4 years ago

    Jose: You can change the for loop in the script to count the other way. But you can also just reverse the video in iMovie.

    Tommaso
    3 years ago

    I confirm that error “Error -1728: Can’t get object.” is due to a localisation problem. You need to change the line 3 of the script (here is an example with French localisation):
    var slideMaster = presentation.masterSlides["Déclaration"];

    Melodie
    3 years ago

    I'm not familiar with writing script. I tried to copy and paste your script and just changed the seconds to 900 because I need a timer for 15 minutes. It worked but there is no text in the 900 slides it created. What would the script be for 15 minutes? Help please! I also don't have the slide option for statement in my Keynote. Only "Title - Center".

    3 years ago

    Melodie: 900 is 15 times 60, so that is right. Not sure why you aren't getting text. Maybe you are using a much older version of Keynote? Try it with another template or the exact one I used.

    Brian
    3 years ago

    A small update to the javascript code to start at HH:MM:SS and go i seconds

    var Keynote = Application("Keynote");
    var presentation = Keynote.documents[0];
    var slideMaster = presentation.masterSlides["Statement"];

    // Define start of clock (Here 07:30:00)
    var start_h = 7; // Starting Hour
    var start_m = 30; // Starting Minute
    var start_s = 0; // Starting Second
    var total_s = 120; // Total number of seconds to create

    var h = start_h;
    var m = start_m;
    var s = start_s;

    Brian
    3 years ago

    for (var i=start_s; i <= total_s+start_s; i++) {
    if (i % 60 === 0) {
    m = m + 1
    if (m % 60 === 0) {
    h = h + 1;
    m = 0;
    if (h % 13 === 0) h = 1;
    }
    }
    s = i % 60;

    clock_str = String(h).padStart(2, '0') + ":" + String(m).padStart(2, '0') + ":" + String(s).padStart(2, '0');
    var newSlide = Keynote.Slide({baseSlide:slideMaster});
    presentation.slides.push(newSlide);
    newSlide.defaultBodyItem().objectText = clock_str;
    }

Comments Closed.