Search

Friends

Atomspheric CO2 (PPM)

Archives

Blather

Uptime verified by Wormly.com

13 August 2007

iTunesAlarm.js

I made a gentle alarm with Dell BIOS timed start, TweakUI autologin, Windows Scheduler, iTunes and some nifty COM scripting. It starts playing music really quietly, and slowly gets louder.

/* iTunesAlarm.js / Version 2 */

var WshShell        = WScript.CreateObject("WScript.Shell");
var iTunesApp       = WScript.CreateObject("iTunes.Application");
var mainLibrary     = iTunesApp.LibraryPlaylist;
var mainLibrarySource   = iTunesApp.LibrarySource;
var alertTimeout    = 5;  // seconds
var alarmFadePeriod = 60; // minutes
var alarmClosePeriod    = 60; // minutes

// Turn it right down
iTunesApp.SoundVolume = 0;

// Play the "Alarm" playlist
mainLibrarySource.Playlists.itemByName("Alarm").PlayFirstTrack();


// Slowly fade in over alarmFadePeriod seconds
for (i = 1; i <= alarmFadePeriod; i++) {
    iTunesApp.SoundVolume = i * 100/alarmFadePeriod;
    if(WshShell.PopUp("Do you want to cancel the alarm?", alertTimeout, "iTunes Alarm", 32+4)==6) {
        WScript.Quit(0);
    }

    WScript.Sleep(1000*(60-alertTimeout));  // Quarter-minutely (25 mins)
}


for(i = 1; i <= alarmClosePeriod; i++) {
    if(WshShell.PopUp("iTunes will stop and Windows will hibernate in " + (alarmClosePeriod+1-i) + " minutes. Let iTunes continue playing?", 60, "iTunes 

Alarm", 32+0)==1) {
        WScript.Quit(0);
        break;
    }
}

iTunesApp.Stop();
WshShell.SendKeys("^{ESC}uh{ENTER}"); // Hibernate

I created a better version instead of doing my econometrics homework. This one has notifications which make it a bit more good. It also turns iTunes off (and hibernates) unless I tell it not to, for those days when I stay at mum's and forget to turn off the alarm. I am teh l33t h4x0r.

Update: [2007-08-19] I changed it so that the fade in lasts longer, and it sets the iTunesApp.SoundVolume to 0 before it starts play. Playing computer was sufficiently sleepy this morning that it was playing at full volume for a few seconds before it got to the loop where it reduces the volume. I got a bit of an abrupt wake up.

The old version is over the fold.

/* iTunesAlarm.js / Version 1 */

var iTunesApp = WScript.CreateObject("iTunes.Application");
var mainLibrary = iTunesApp.LibraryPlaylist;
var mainLibrarySource = iTunesApp.LibrarySource;

// get all playlists
var playlists = mainLibrarySource.Playlists;

playlists.itemByName("Alarm").PlayFirstTrack();

for (i = 1; i <= 100; i++) {
    iTunesApp.SoundVolume = i;
    WScript.Sleep(10000*15);  // Quarter-minutely (25 mins)
}

Comments

  1. It worked this morning and it was so good. How pleasant to wake up to quiet music when you’re ready for it. The other nice thing is if you wake up and go back to sleep you know that eventually it will get loud enough that you’ll wake up again.

    Ryan / 7:44am / 14 August 2007

Leave a comment

Markdown

0.085 seconds