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


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: 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 | # ]