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.
You can also watch this video at YouTube.
Watch more videos about related subjects: iMovie (137 videos), JavaScript (14 videos), Keynote (147 videos).
You can also watch this video at YouTube.
Watch more videos about related subjects: iMovie (137 videos), JavaScript (14 videos), Keynote (147 videos).
Video Transcript
Hi, this is Gary with MacMost.com. Today let's create a clock timer that we can use as a video overlay in an iMovie project.
MacMost is brought to you thanks to a great group of more than 750 supporters. Go to MacMost.com/patreon. There you can read more about the Patreon Campaign. Join us and get exclusive content and course discounts.
So sometimes you need a clock in iMovie. Something that's either counting up or counting down to be an overlay in your video. We're going to create something in Keynote that can act as a clock counting off each second and make it reusable so we can use it in different situations over and over again.
We're going to start in Keynote. We're going to go and create a presentation using the basic black theme. Now here we're going to add a new slide. We're going to choose a slide where we can just put a big number in the middle of the screen. A good one for this is the Statement slide in the theme. So now we just have text in the middle and I can click on it and then let's put in something like two minutes just to get an idea what it will look like. Now this is pretty small. We want it to fill the entire thing. Even if we want it small inside of iMovie we want to make it as large as possible here in Keynote because we can shrink it in iMovie very easily.
So I just don't want to change the text here. I want to change how it is in the theme so when we create new slides using the statement slide we get the same font. So let's go to View, Edit Master Slides. Then we're going to select Statement here. It's already selected because that's the template used by our current slide. It just has this one text box in the middle. Don't worry about what it looks like in here. We just want to change the font. So let's go to Format, Text and first let's pick a better font. You could choose whatever you want. I'm going to choose Menlo. It's a monospaced font. Numbers look good in it, I think. I'm going to make it Bold and I'm going to make it much, much bigger. So let's go, to say, to 1000 points. Then I'm going to increase the space here for this text box. Once I do I'm going to recenter it.
Now let's exit the Master Slides mode here and now we see it has changed this. So now we have a nice, big time in the middle of the slide. Now as I said you could use any font, any size that you want. You could also even use a different color. But I like using white and we'll be able to make some adjustments. I like using white here as the overlay. The black background we're going to get rid of.
But first we need to create a slide for every second that goes by. So we want to start here, say, with zero and then we want to add a new slide using Statement. Then this one will be 0:01 and then we can continue to do that. It's easier if you select the slide here and do Command D, that's edit. Duplicate selection and now we can go in and just make a change here. You can actually do Command D a bunch of times to create the different ones. Go to each one and make a change. This really won't take that long. Give yourself 15 or 20 minutes and you'll be able to go up to two minutes or three minutes or however much you want.
But I'm going to use a script to do it because I'm lazy. So let's select all of these. I'm going to delete them. So clear out the presentation. Don't worry about the default slide here that's stuck. We'll just delete that at the end. I'm going to switch to Script Editor. Script Editor is an app that comes with your Mac so you've got it. I'm going to go into Script Editor and create a new document.
Now if you don't like scripting and you don't know programming at all don't worry. I'm going to give the entire script to you. It's a pretty simple script. I'll explain what it does but you can just Copy and Paste it if you want.
The important thing I need to do first though is change from Apple Script to Java Script. If you don't do that this won't work. Now I'm going to paste the script in. So you can see it's not really that many lines. The first three lines just set three variables. Set the variable Keynote to the Application Keynote so we know to refer to the Application. Sets the variable presentation to the current document. So make sure you have Keynote open with just this one document ready to go. Then we're going to set slideMaster equal to the template slide named Statement. Then we're going to loop. We're going to start with zero and go to 120. Two minutes of time in seconds. We're going to get the number of minutes and put it in m so that's just the number of seconds divided by 60 rounded down. Floor means round down. Then we're going to get the number of seconds left over by taking the total number of seconds and subtracting however many minutes there are times 60.
Then we create a new slide and you could see here we're using that slideMaster so referring to the Statement slide. We're going to push that onto the presentation. Then we're going to set the body text, which is this here, to minutes and then a colon and then seconds but we're going to surround it with all of this basically just to pad it with zeroes. So 3 is zero 3 instead of just 3.
Now let's move this over here and we can see the presentation underneath. When I run it you'll see it add these 120, actually 121, slides because it starts from zero to 120. You could see it add it all. That's a lot faster than doing it manually. Now we can see each time in each slot. We can go back to the beginning. We can see we've got that slide here at the beginning. We can just delete that. Hit the Delete key. Now we're starting at zero going to 120 or two minutes.
Now the next part if very important. You want to select a slide here, like the first one, Command A to select All. So all the slides are selected. Then go to Format and under Format make sure you see Slide Layout and change the background color to No Fill. This should set the background color of all the slides to nothing. So if I select slide 3 and I look at Format, Slide Layout, background is No Fill. If I select Slide 6 is also No Fill. If all the slides aren't set to No Fill then this won't work. Now let's Export.
I'm going to do Export to Movie. Now I'm going to select Self Playing. I'm going to do All Slides and I'm going to go to the next slide exactly after one second. So every slide will be there for one second. I'm going to change the Resolution to Custom and then go to 1920 by 1080, which is typical for iMovie videos. Then we need to switch to Apple ProRes 4444 and make sure Export with Transparent background is checked. If this isn't checked or it's grayed out then you haven't set all the slides to No Fill or you forgot to go to Apple ProRes. If this isn't transparent, well, this isn't going to work very well.
Now we'll go to Next and we'll export this out as a video. I'll call it Timer and I'll export out all the slides so we have a video we can use in iMovie. Now I can look here on the Desktop and here's the Timer movie. I can double click on it to open it up in QuickTime Player and I can see it's two minutes and two seconds long which makes sense because remember we have zero and two minutes so it's actually two minutes and one second long. There's a little tiny bit extra at the end of a Keynote Export and it's going to round it up so it's two minutes and two seconds. Every slide is still just exactly one second. We can scrub through here. So now we're ready to go.
So now here's my iMovie project. I just have some sample video in here. Chances are if you have a clock on the screen it's probably going to be you talking about something and counting down to a time or something like that. I'm going to bring this video in and I'm going to add it to the top here so it's going to be an overlay to the existing video. I'm going to select it and make sure I go here to the video overlay settings and I'm going to change it to Picture-in-Picture. Now here you can see the timer is right here. I can move it around to wherever I want. So I can put it here at the bottom right. I can stretch it and make it as large and as small as I want. You could see here it's going to count the seconds.
If I wanted to get rid of something, like maybe the zero second, I could always trim the beginning of the video so I could start at one. I could also easily reverse this by clicking on the speed control here and clicking reverse and now I get something that starts at 2 and counts down. The Picture-in-Picture thing here automatically has a dissolve here of five seconds. I can take that away and go to zero seconds so now it just appears there and now it's counting down and I could put that wherever I want.
I can even play with the color. This is why I made this white. I can go here to Colors and I could grab this end here and bring it down and then change the tint, maybe make it blue or yellow. If I really wanted a specific color I could go back here in Keynote and go to View, Edit Master Slides, Edit this statement here to change the color for this template slide. So let's go and change it to a red. Now when I Exit Master Slides you can see all the numbers are red. I can export this again. I could also go and add a shadow to this. So I can select here under Style, go to Shadow, and I could create a drop shadow for it. It's hard to see here because it's on a black background.
Now if you really want to get creative you can try adding transitions between each slide just like all the slides in a Keynote presentation, add a transition. You have to have a minimum time for a transition. So if you set the transition for one second and then you also have one second between slides you end up with a video overlay that's twice as long as it needs to be. So two minutes would actually be four minutes. So you want to change the speed of that video and make it 200% fast. That way it takes your four minutes to countdown from two minutes and compresses it back down to two minutes.
You could do all sorts of other things too. For instance for the last ten seconds you could change the color. Make them red, make the font get bigger, all sorts of things like that. The sky is the limit for what you want to do once you have that Keynote presentation you can really customize it as you like.
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'); }
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!
Jack: You can just change the for loop. It counts from 0 to 120 now, so make it count from 120 to 0, like:
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 ')'
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.
That did it! Thank you very much.
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.
TQVM Gary, for another great and enlightening video.
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
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.
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.
I actually got it ! THANK YOU SO MUCH. literally your video was the only helpful video i found!!
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')
Isaac: Just try going through everything step-by-step and setting it up the same way I do.
Hi Gary, is there a way to add a voice or sound to the last seconds of the timer?
Marie: I would just record that yourself as an audio VoiceOver.
This was so INCREDIBLY HELPFUL. Thank you for the simple, easy to follow instructions.
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.
Alyssa: That error suggests that maybe your open Keynote document isn't set up the same as what I am showing in the tutorial.
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 "Информационное сообщение".
Andrew: Not sure. Sounds like an issue with the language settings and just getting everything to match right.
Hi Gary, the script is working creating the slides but not writing in the slide the result. How can i solve that?
Christian: Perhaps an issue with the template's text boxes? Try another template.
Hi Gary, the coding was succeed until automatically creating the slides. But the time is not showing. How can I solve this?
Risjad: Impossible for me to tell what could be wrong with how you did it. Try again following every step carefully.
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?
Joss: No, it will work in Big Sur. Be sure your Keynote document looks like mine.
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
Hi Garry I got Error- 1700: Can't convert types?
Jenny: Make sure your script and the Keynote presentation are exactly like I have them.
Thanks - This was just what I needed :-) It's working perfectly...
For 10mins... would it be this? (var I=600;i>=0;i--)
Thanks In advance!
James: yes. Lowercase i, of course. then a -- (two dashes) at the end.
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?
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.
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"];
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".
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.
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;
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;
}