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

Use iCal to launch scripts on any schedule Apps
I was reading hints on this site regarding scheduling of various OS X maintenance jobs (repair permissions, etc). Quite a few of these were based on Terminal scripts or AppleScripts, both of which work fine. The debate usually focused on the best way to launch these scripts, using cron or placing scripts in the daily routines folder, or using Cronnix, you get the idea. Well, it turns out all you need is the latest version of iCal!

When you create a new event if you click "Alarm," you get several choices, one of which is "Open File." Yup, this can open anything you want including, of course, AppleScripts. Simply select the script you want to run, choose the time of day and interval, and you're off! Plus these will run even if iCal is closed, just like any other alarm message.

Combined with the new (born again!) scheduling feature in Panther's Energy Saver panel, this makes for a quick and easy method for running maintenance jobs (or anything else you want) before your first coffee in the morning.
    •    
  • Currently 2.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[8,121 views]  

Use iCal to launch scripts on any schedule | 12 comments | Create New Account
Click here to return to the 'Use iCal to launch scripts on any schedule' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use iCal to launch scripts on any schedule
Authored by: SOX on Nov 21, '03 12:42:10PM

I've noticed that ical does not send alerts if the alert passes while the ocmputer is asleep. you still need anacron to catch these



[ Reply to This | # ]
Use iCal to launch scripts on any schedule
Authored by: shneusk on Nov 25, '03 01:51:10PM
this program will wake your machine from sleep on a schedule. I'm sure there are others too.

[ Reply to This | # ]
Use iCal to launch scripts on any schedule
Authored by: mm2270 on Nov 21, '03 01:14:03PM
I would like to be able to use this hint by having iCal running periodic scripts, but I'm not sure hwo to begin.

I know from previous hints how to use:
sudo periodic time_period in the Terminal to run scripts, but does anyone know the correct syntax to have these executed from within an Applescript? I believe AS can invoke shell scripts, etc. now, right?
I would want the script to run with automatic authorization of my admin account, since I don't have to be concerned about security, as this is just my home Mac that noone else uses.

If anyone has an idea about how to do this, I would greatly appreciate a little advice. Thanks.

[ Reply to This | # ]
Use iCal to launch scripts on any schedule
Authored by: paulrob on Nov 21, '03 06:21:38PM

Applescripts can be run from another Applescript with the line

run script("XXX:XXX:XXX:XXX" as alias)

where XXX:XXX:XXX:XXX is an Apple path to the script (NOT UNIX path)

UNIX scripts can be run as root from Applescript with the following line

do shell script("your command line text here") password "your user password here" with administrator privileges

Example

do shell script ("chmod a+rwx ~/desktop/data.txt") password "censored" with administrator privileges
this is equivalent to "sudo chmod a+rwx ~/desktop/data.txt" typed at the command line

Check AS Standard Additions dictionary for more

Ummm! I'm not sure what exactly you are attempting but:-

1. If you are trying to get periodic to execute at times other than those specified in /etc/crontab because your computer is off or asleep at these times, then it will probably pay to change the times in /etc/crontab rather than generating loads of events in iCal.

2. Periodic is designed as a system function - called by cron to run scripts that service the system when the system is on but unused. It not supposed to be called directly by the user. Be aware that periodic executes all scripts in its directories not just yours. These include scripts that (weekly) rebuild the locate file database for example. Theoretically, performance of applications that you might be running could be affected if you call periodic directly at the wrong moment. It is better to insert lines specifying when your scripts should be run in /etc/crontab. See this hint on how to do this: http://www.macosxhints.com/article.php?story=20031017053141796

3. If you want to use iCal as a scheduler (for occasional scripts) why don't you have IT call the shell script using a AS file containing the line above starting "do shell script ..." rather than periodic.

Hope this helps

TTFN



[ Reply to This | # ]
Use iCal to launch scripts on any schedule
Authored by: mm2270 on Nov 21, '03 11:11:44PM

Hey paulrob-

Thanks for the hints, and for the advice. I suppose I could just change the time the scripts run in crontab, as you mentioned. Would probably be better to do that. I suppose I could also use the new Energy Saver settings to have my Mac wake up in the middle of the night during the time I want the scripts to run, so I don't have to be bothered with them running during the day when it's being used.

Anyway, thanks for the tips, they gave me some ideas.



[ Reply to This | # ]
Use iCal to launch scripts on any schedule
Authored by: zthompson47 on Nov 21, '03 01:57:42PM

I played around with the Alarm feature of iCal, and it looks like iCal has to actually be running at the time of an alarm for the alarm to be triggered. Too bad iCal doesn't use cron to run alarms so it wouldn't have to be left running...



[ Reply to This | # ]
Use iCal to launch scripts on any schedule
Authored by: gopes on Nov 21, '03 04:14:22PM

I had set up iCal to run an AppleScript that would blast music to wake me up in the morning. It worked once, so I don't know what's up with that... Also, more strangely, iCal sometimes wouldn't show a message (for a different alarm) at all, even if it was running, but it displayed the message once when iCal *wasn't* running. I thought that the faceless iCalHelper app was supposed to take care of this, and it with the last version, but 1.5.1 broke it for me...



[ Reply to This | # ]
Use iCal to launch scripts on any schedule
Authored by: Faux Plastic on Nov 21, '03 04:42:33PM

As you can see in my other post in this thread, I use iCal a lot to open files on a timed basis. I agree that it has some bugs in it. The one tip I can offer is about the timed event working only once. Did you set it as a repeating event or have you been dragging/cutting-pasting the same event from day to day as needed? I have found that you can't do either (dragging or cutting-pasting) to an event that has already performed its timed function at least once. Or rather, you can, but the timed event won't work again.

It seems that events have a hidden status that records whether it has already performed the timed event or not. So if you use it to sound an alarm today and when it's done you move it to next Tuesday, it won't go off because it has a status recorded that it has already performed its timed event.

So basically unless you can set the event up as repeating, you will have to make a new alarm every time.



[ Reply to This | # ]
Use iCal to launch scripts on any schedule
Authored by: Faux Plastic on Nov 21, '03 04:32:03PM

I use this all the time to run applescripts and to open iTunes, RealOne, and Windows Media streaming audio so that I can listen to varous NPR programs throughout the day when they come on (I live out of range of a genuine radio signal).

I suppose if I wanted to, I could also use this to do some timed recordings of my favorite shows. Once it's set up, it would about as easy to use as setting the VCR, which ain't too tough for a geek. But I haven't gotten around to that yet.



[ Reply to This | # ]
Use iCal to launch scripts on any schedule
Authored by: bluehz on Nov 21, '03 07:13:28PM

HAHAHAHAHHAA
HAHAHAHHAHAHAHAH
You make Gronk laugh!!!

Heck I would be happy if I could just get iCal to notify me of the events for which I have set alarms for and which I need to be notified of. In theory thats what a PIM (Personal Info Manager) like iCal is used for. I love Apple - through and through an Apple junkie - but iCal which is supposed to be PIM and have the capability of notifying you of events - is just not ready for prime time. Sometimes events notify, sometimes not. Its hit or miss.... and mostly MISS!!!

... and before you start... I leave my machine on 24/7 so thats not the problem. Take a few rounds in the Apple Discussion boards and you will see this problem is rampant with users throughout.



[ Reply to This | # ]
Use iCal to launch scripts on any schedule
Authored by: sjmills on Nov 21, '03 07:30:15PM
Sadly, iCal events don't fire if you reboot your Mac and don't launch iCal. I'd hoped they would fix this in 10.3, but it doesn't look like they have.

[ Reply to This | # ]
Use iCal to launch scripts on any schedule
Authored by: biggyfishy on Nov 23, '03 08:10:42PM

Why don't you just add iCal Helper to your Startup items (nee Login items)?

It's located in the iCal bundle:
/Applications/iCal.app/Contents/Resources/iCal\ Helper.app



[ Reply to This | # ]