Filed under: Audio, Features, Windows, Productivity, Apple

How to make a poor man's alarm clock with iTunes on Windows

Green alarm clockEvery media player ought to include a simple alarm clock, but unfortunately with iTunes that's not the case. Certain plugins and third-party programs exist that get the job done, but for iTunes on Windows, at least, they are either of questionable quality or cost money. Fortunately, it's possible to get rudimentary alarm clock functionality in iTunes for Windows with little more than a text editor. Instructions after the jump.

Create the JScript

First, we have to create a JScript (Microsoft's version of JavaScript which can be used to control and interact with some Windows applications, including iTunes) file that tells iTunes to start playing. Start Notepad and enter these two lines:

var iTunes = WScript.CreateObject("iTunes.Application");
iTunes.Play();

The first line says, "create a JScript object that I can use to control iTunes," and the second tells that object to make iTunes play. Save the file with a sensible name ending in ".js," like "iTunesPlay.js," making sure that Notepad doesn't automatically add ".txt" or anything else to the end of the filename.

Test the script

Now we can test to see if our new script works. Go to Start and Run and enter "wscript" followed by a space and then the full path to the script you created. If there are any spaces in the path, you may need to enclose it in quotation marks, e.g.:

wscript "C:\Documents and Settings\Jordan\scripts\iTunesPlay.js"

Make sure your speakers are on and iTunes isn't already playing and click "OK." Your iTunes should begin playing whatever song is currently queued up.

Set the alarm

In order to make iTunes play at a particular time, all we have to do is use Windows' Task Scheduler to schedule our script to run at that time. Go to the Control Panel and Scheduled Tasks and choose "Add Scheduled Task" to lonk the Scheduled Task Wizard.  Click on "Next" and on the choose-a-program screen click on "Browse..." Browse to your Windows folder (usually c:\windows or c:\winnt) and then the system32 folder. In system32 double-click on wscript.exe. Back in the Scheduled Task Wizard, give your task a name like "Play iTunes" and pick how often you want the task to run. If you want it to run every day or every weekday choose "daily;" if you only want it to run on, say, Tuesdays, Wednesdays, and Fridays, choose "weekly." Then click on Next. On the next screen you can tell it what time you want the script to run and what date you want the task to start. Set your options and click Next.

On the next screen you'll have to enter your Windows login and password. The Wizard ought to fill in your login name for you, so enter your password twice and click Next. On the last screen it will confirm your settings. Check the "Open advanced properties for this task when I click finish" box and click Finish.

In the Properties dialog that opens you'll see that the "Run" box shows the path to wscript.exe, but we still have to point it to our script; otherwise, it will do nothing. Immediately after "wscript.exe" enter a space followed by the full path like you used before, again in quotes if necessary. Make sure it is the name of this script, e.g. "iTunesPlay.js," is included. Now click OK. You may be prompted to enter your password again, and then you're done! If you want, you can test your task by right-clicking on it and choosing "Run." You can change the schedule any time by double-clicking on the task and going to the Schedule tab.

Further reading

For more information on Windows Scripting Host, which you just used to make a text file control an application, take a look at the Scripting section on MSDN. For more information on controlling iTunes with scripts in Windows, Apple's iTunes COM for Windows SDK has documentation and example scripts.