Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'great idea, but hey, use cron!' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
great idea, but hey, use cron!
Authored by: vibrato on May 13, '02 11:47:37AM

Hi, I tried your cron-based solution but for some reason the shell script only works from the command line but not when run from cron. The time and wake up prompt work fine but iTunes launches without playing a track. The only thing I can think of offhand is that I do have OS X installed on an external drive and my MP3s on the drive in my PowerBook but I don't see that affecting the script in any way (since it works from the command line). THX



[ Reply to This | # ]
great idea, but hey, use cron!
Authored by: wealthychef on May 13, '02 05:25:14PM

You are right. I pared my example to this, and it still didn't work. Anybody know why?
#!/bin/sh

echo "tell application \"iTunes\" to play (some track of playlist \"Library\" whose artist is \"Alanis Morissette\")" | /usr/bin/osascript

If I run this from the prompt, no problems, it works. If I run it from a cron job, I get the following error:

syntax error: Can't get the application's event dictionary. (-2709)



[ Reply to This | # ]
great idea, but hey, use cron!
Authored by: wealthychef on May 13, '02 08:33:40PM

From everything I can tell, you cannot run applescripts from cron. So the only thing to do, would be to compile the arguments to osascript into little applications with AppleScript Editor, and call them from your script using \'open.\' For example, instead of the line:
echo \"tell application \\\"$music_app\\\" to play (some track of playlist \\\"Library\\\" whose artist is \\\"$artist\\\")\" | /usr/bin/osascript

You would put the line:

tell application \"iTunes\" to play (some track of playlist \"Library\" whose artist is \"The Rolling Stones\")

into a text file and use Applescript Editor to compile it into an application, say /Users/mylogin/StartPlayingStones

Then the line above becomes:
open /Users/mylogin/StartPlayingStones

and life is good again.
I didn\'t fully test this in the alarm clock context, but was able to confirm that cron can handle a shell script with that \'open\' command in it just fine.



[ Reply to This | # ]
great idea, but hey, use cron!
Authored by: wealthychef on May 13, '02 08:54:34PM
For more info on the cron thing, see: This thread at bbs.applescript.net

[ Reply to This | # ]