image
image

|


Go Back   macosx.com > Mac Help Forums > HOWTO & FAQs

Closed Thread
 
Thread Tools
  #1  
Old October 29th, 2001, 02:16 AM
Registered User
 
Join Date: Jul 2001
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
tieng is on a distinguished road
Finally--iTunes alarm clock

A feature I've been waiting for, but it took procrastinating for a big test and a project to finally get me to sit down and figure it out.

This makes use of AppleScript and Cron. It also assumes you have a playlist that opens by default in iTunes.

First, open Script Editor and type this stuff in. Note that when I say << and >> in my code, I mean the character generated by option-\ and option-shift-\

Code:
tell application "iTunes"
   -- I have it skip to the next song, in case 
   -- we stopped in the middle of playing something.
   << event hookNext>>
   -- this next part sets a nice volume for waking up to.
   -- omit if you'd like
   set counter to 20
   repeat until counter  = 0
        << event aevtvol->>
        set counter to counter - 1
   end repeat
   set counter to 10
   repeat until counter = 0
         << event aevtvol+>>
         set counter to counter - 1
    end repeat
    -- this next line actually starts playing iTunes
    << event hookPlay>>
end tell
Compile the script as an Application and save it somewhere under a name you can remember. I have mine saved in /Applications under Play, but you can put it anywhere you'd like. Test it, and make sure it starts iTunes playing when you double click on it.

Apple provides a command line utility called "open" that makes the argument you pass it behave as if you've double clicked on it. Fire up a terminal and try

open /Applications/Play

substituting where you put it and what you named. If it works, then you're a little closer.

The next part is good stuff...we use the Unix utility cron to automatically execute it when ever you want to wake up.

A cronjob is specified thusly by saying crontab -e from the command line:

Minute Hour DayOfMonth MonthOfYear DayOfWeek [Command]

You can specify valid numeric values for each of the options, or stick in a * for it to run [command] every time a valid option comes up.

So if you wanted to execute something every Monday and Thursday at 1:25 PM, you'd say:

25 13 * * Mon,Thu [command]

Or the first and fifteenth of January and June at 2:38 pm, you'd say:

38 15 1,15 1,6 * [command]

Or in our case, at 8:15 am every weekday morning, you'd say:

15 08 * * Mon,Tue,Wed,Thu,Fri /usr/bin/open /Applications/Play

Cron opens in the vi editor by default, so after you've made the entry you want (and you can make as many as you want) you should hit the escape button, then :wq to exit vi.

You may want to put a few testing entries in there to make sure you're working right, but other than that, you should be set! Good luck, and post here to let me know how it goes!

NOTE: Cron wants the last line in the file to be a new line, so make sure you hit return a couple of times after the last crontab entry in your file.

Thanks go out to the good folks at www.applescriptcentral.com, especially <a href="http://www.barzeski.com">erik</a> for helping me get this working.

Last edited by tieng; October 31st, 2001 at 01:00 PM.
  #2  
Old October 29th, 2001, 09:47 AM
Soapvox's Avatar
Want some of my Kool-aid?
 
Join Date: Apr 2001
Location: Advertising Hell
Posts: 412
Thanks: 0
Thanked 0 Times in 0 Posts
Soapvox is on a distinguished road
Quite Nice

Man I love OS X!!!!!!!!!!

Lets see XP do that, thanks for the great script!
__________________
G4 Powerbook (I Finally got my Titanium)
PHP/MySQL

Developing where ever I want!
I will help whomever asks, just IM or email me.
  #3  
Old November 3rd, 2001, 07:42 PM
MacHead
 
Join Date: Oct 2001
Location: San Fernando Valley, CA
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
yanges is on a distinguished road
Re: Finally--iTunes alarm clock

hey tieng!

that looks like a great script ...i am gonna give it a try.....

one thing, does it work if the computer goes to sleep? i guessed it would due to using cron, but not sure....

thanks
__________________
yanges

dual 2.0ghz PowerMac, Tiger, 1gb ram, 19" Viewsonic CRT display, HK SoundSticks, iBot - Cube 450mhz, OSX.2, 1.2gb ram, Apple CRT 17" Studio Display
  #4  
Old November 4th, 2001, 07:02 PM
jove's Avatar
Member
 
Join Date: Nov 2000
Posts: 555
Thanks: 0
Thanked 0 Times in 0 Posts
jove is on a distinguished road
Go to www.versiontracker.com and search for cron

CronniX is a nice little GUI to edit cron jobs
And there is a program to deal with the sleep issues but it looked like to much of a hassle.
__________________
Jove
Talk doesn't cook rice.
  #5  
Old November 4th, 2001, 08:58 PM
scruffy's Avatar
Notorious Olive Counter
 
Join Date: Dec 2000
Location: Soviet Canuckistan
Posts: 1,726
Thanks: 0
Thanked 0 Times in 0 Posts
scruffy is on a distinguished road
There is also a program called mp3 alarm clock, on versiontracker
__________________

What is the robbing of a bank compared to the founding of a bank?
-- Bertold Brecht
  #6  
Old November 6th, 2001, 12:42 AM
Registered User
 
Join Date: Jul 2001
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
tieng is on a distinguished road
iTunes 2.0

Just a quick update to the script...

iTunes 2 is much more scriptable; although they will still work, you don't need to do the event hookNext and event hookPlay commands. You can just use "play" and "next"

I don't believe cron will wake up a sleeping computer. And from what I can tell about Tempus (the utility mentioned above to perform cron jobs while sleeping) it won't actually wake up a computer to run the job. The first time the computer wakes, tempus will check to see if any cron jobs were supposed to have been run with the computer was sleeping.

So, if you used Tempus to run all this stuff, it would start playing music after you manually woke the machien up. You'd probably have missed your classes or work by then, though. Safest bet is still just to leave your computer running and not sleeping. (You should use all those extra cycles at night for something useful, like , encryption research, curing diseases or finding life on other planets.)

  #7  
Old November 6th, 2001, 04:28 AM
symphonix's Avatar
Scratch &amp; Sniff Committee
 
Join Date: Jul 2001
Location: The Australian Jungles
Posts: 4,021
Thanks: 2
Thanked 1 Time in 1 Post
symphonix is on a distinguished road
Here's an alteration to that trick that might be a little easier, in that you can skip all the AppleScript stuff.
If there is a particular song you like to wake up to, for this example I'll call it "Start Me Up.mp3", then you can add a line to your /etc/crontab file with the command
open "/MusicFolder/Start Me Up.mp3"
Regardless of what iTunes is doing, it will start playing that song when the Cron event is tripped. Ain't it sweet?
__________________
- iMac G5 1.8GHZ 17" | SuperDrive | 160GB | 512MB | Airport Extreme | Bluetooth Keyboard & Mouse | Wacom Intuos II
- Pentax *ist DL - JVC MiniDV Camcorder - Airport Express - iPod Nano 1gb white
  #8  
Old November 6th, 2001, 08:37 PM
MacHead
 
Join Date: Oct 2001
Location: San Fernando Valley, CA
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
yanges is on a distinguished road
Quote:
Originally posted by symphonix
Here's an alteration to that trick that might be a little easier, in that you can skip all the AppleScript stuff.
If there is a particular song you like to wake up to, for this example I'll call it "Start Me Up.mp3", then you can add a line to your /etc/crontab file with the command
open "/MusicFolder/Start Me Up.mp3"
Regardless of what iTunes is doing, it will start playing that song when the Cron event is tripped. Ain't it sweet?
hey symphonix

that sounds pretty simple except i don't know how to get cron running to insert my info.....
could you give me a some brief directions?

thanks a lot!
__________________
yanges

dual 2.0ghz PowerMac, Tiger, 1gb ram, 19" Viewsonic CRT display, HK SoundSticks, iBot - Cube 450mhz, OSX.2, 1.2gb ram, Apple CRT 17" Studio Display
Closed Thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[HOWTO] - Make iCal an alarm clock! boi HOWTO & FAQs 16 May 28th, 2005 12:53 PM
[HOWTO] - Change iTunes Visualizer! Trip HOWTO & FAQs 8 October 14th, 2002 02:40 PM
cron alarm clock iknownotwhoiam Unix & X11 7 May 16th, 2002 02:10 PM
cron alarm clock iknownotwhoiam Mac OS X System & Mac Software 1 May 12th, 2002 07:52 AM
iTunes 2 is going nuts! Bloated Temp Files! GadgetLover Mac OS X System & Mac Software 8 April 11th, 2002 04:45 PM


All times are GMT -5. The time now is 11:46 PM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.