MacMost Now 329: Schedule Podcast Updating with AppleScript

Instead of letting iTunes update podcasts every hour or in the middle of the day, you can schedule iTunes to check at night. Using a simple AppleScript and scheduling it to run with iCal you can have new podcast episodes waiting for you when you get to your Mac in the morning.

Video Transcript
Hi, this is Gary with MacMost Now. On today's episode lets use AppleScript to schedule podcast updates in iTunes.
So I often hear that people are frustrated by iTunes lack of options for updating podcasts. Either you have to update every hour or at the same time everyday. People want to be able to set iTunes to update, say in the middle of the night just once a day, so they have fresh new podcasts waiting for them in the morning. Well you can do this using AppleScript. So this is a good opportunity for us to look at how to use some basic AppleScript. Lets create one and then schedule it to run in the middle of the night using iCal.
So you can find the AppleScript editor in the 'Utilities' folder in the 'Applications' folder. Once you run it, you get a scripting window like this where you have to type in commands. Now if you're not a programmer AppleScript probably isn't a very good programming language to start with. But you can find lots of example AppleScripts all over the internet by searching for 'AppleScript', followed by a description of what it is you're looking for. So for instance you can find information about how to update podcasts in iTunes. Lets start with a line here that tells us to point the AppleScript at iTunes. So 'tell application "iTunes"', and the first line is 'activate'. This will either run the program iTunes or it will bring it to the front if it's already running. Now the next is a specialized command; well there's no way of knowing that it exists unless you're specifically looking for it or happen to stumble upon it on the web. 'UpdateAllPodcasts'. That'll basically be the same as hitting the refresh button in the podcast section of iTunes. Then we 'end tell'. So we're going "Tell application iTunes to activate, update all podcasts." Now we click the 'compile' button, we can see that a format's attached and it gives a clue that we've probably typed the right thing.
So we want to test this out by hitting 'Run'. And if it works it should launch iTunes and then automatically update the podcasts. Lets see if it does. I click on it and I can see that it is indeed running iTunes. There's iTunes there and we can see now it's downloading one item, it actually did go ahead and update the podcasts. And now if I click on the MacAnswers podcast I can see it updated it with the most recent episode.
So now we just have to save this script out. We save it as, lets just call it 'Update Podcasts. I'm going to put it on the desktop here, but you'll probably want to put it somewhere else, like in your documents folder. We're going to keep it as format 'script' because iCal can actually handle AppleScript scripts; you don't have to save it as an application. And we'll hit save.
So in iCal lets create a new event, and we're going to call it 'Update Podcast'. We're going to set an alarm for this podcast as 'Run Script'. And then we're going to select the 'Update Podcast' script right here. Once you select a script like this it will actually appear in a list here - you can see 'Run Script' and then 'Update Podcasts' appears in that list. And then we're going to set it to run at zero minutes before, so it'll run exactly at the time that we've scheduled. We're going to change the time here so that it runs at 3:01 AM and ends at 3:01, and we're going to set it to repeat everyday, to repeat everyday at 3:01 AM. We're going to click done, and we can see it's scheduled here. Now what'll happen is if your machine is awake it will then launch this script at 3:01 AM and begin iTunes, updating the podcasts. But if your machine is asleep it won't run. If your machine is awake though, you don't need to have iCal running - I should point that out. iCal schedules, like this, alarms, whatever they are, will run regardless of whether or not iCal, the program itself is running because there's a process on your Mac that runs iCal alarms regardless. It wouldn't be very useful if we always had to keep iCal running all the time.
Now what happens if your machine does go to sleep or if you put it to sleep every night? Well you can simply tell it to wake up a minute before the script is set to run. Just go to 'Energy Saver' and go to 'Schedule', and in there you can tell it to start up or awake everyday and you can set it to 3 AM. So now we know that your computer will be awake when that calendar event has to run.
So if you're a programmer you may want to continue to look into AppleScript. There's a lot of different casts that you can script, even beyond what Automator can do. There's a library inside the AppleScript editor that you can browse through and a lot of online resources as well you can search for. Hope you've found this useful. Til next time this is Gary Rosenzweig with MacMost Now.

Comments: 11 Responses to “MacMost Now 329: Schedule Podcast Updating with AppleScript”

    12/10/09 @ 9:08 am

    You say updateAllPodcasts, “is a specialized command, well there is no way of knowing that it exists unless you’re specifically looking for it…”

    Or unless you browse through the scriptable objects and commands in the iTunes Script Dictionary, which is what you should do when you want to try scripting anything… read it’s script dictionary. To do this, Go to AppleScript Editor > File > Open Dictionary… then choose the app you want to script.

    Searching on the web is great but why not start right at the source?

    Anyhow, thanks for the great tip.

      12/10/09 @ 12:07 pm

      Well, that is what I mean. You can browse and find it, but I had so many requests from people about a command that would do this that it was obvious that people were looking and still not finding it.

    12/12/09 @ 2:30 am

    Thanks very much for this one Gary. Really appreciate it…billiant!!!

    PS: I would have never worked it out myself in a million years!

    12/12/09 @ 2:32 am

    post 2… typo: brilliant!!!

    1/10/10 @ 8:09 am

    Hi Gary
    I tried to run the script but a get this error message…can you help or suggest a solution…?
    thank you!
    error “The variable updateAllPodcast is not defined.” number -2753 from “updateAllPodcast”

      1/10/10 @ 8:16 am

      The command is “updateAllPodcasts” (with an s at the end).

    1/21/10 @ 4:32 pm

    Hi Gary,
    I am a new Mac user and learn a lot from your podcasts. Question about this scripting.. I set up the script as you described and it works when I have my MacBook pro on. I tried telling the machine to ‘wake’ with the Energy Saver a minute prior to the ical script, but this doesn’t happen. Will the Energy Saver not ‘wake’ if the laptop is closed? Currently, the script will run as soon as I lift the lid of my laptop and type in my password. Am I doing something wrong?

    Thanks in advance!

      1/21/10 @ 4:41 pm

      If you have a MacBook then it must sleep if the lid is closed. (Exceptions are if it has a mouse, keyboard and external screen hooked up). So that’s what’s happening.

        1/25/10 @ 4:56 pm

        Thanks Gary for such a quick response! Keep up the good work with your podcasts. I recommend you to my friends and colleagues.

    3/7/11 @ 5:11 pm

    Hi Gary,
    I found yr Podcast #329 very helpful and very easy to understand. The hardest part was “googling” to find yr web site :) Like Brian I brand new to the mac osx, so I am finding out what is on my mac mini, In doing so I have found this app called “automator” which can do the same thing, So my question is why do we write scripts like “podcast updater” when we can/could use the app “Automator”. Plz remember I brand new to mac’s and I am sure there is a very reason, look forward to yr reply,

      3/7/11 @ 5:19 pm

      Automator is actually just an easier shell put on to AppleScript. A programmer might like to skip Automator and just write an AppleScript. A non-programmer would just stick with Automator and not use AppleScript at all. What Automator does is a subset of what AppleScript can do. That’s why sometimes you have to place a small AppleScript inside Automator to accomplish a task.

Comments Closed.