applescript and cron

I am trying in vain to get cron to run AppleScripts. For the moment I just have a short script that opens access to a file, writes something to it and closes the file again. I can get the script to work from the command line, but it doesn’t appear to work from cron.

I have the script saved as an application bundle (at the moment, I have tried other options) . When I run it from the commandline as “open /testscript” (it is just on the root of the drive) I get a dialog box asking me whether to run or quit the script, which is undesirable. If I run the script as osascript /testscript the scripts completes successfully and without the dialog. Now I just need that to happen using cron.

I have editied the system crontab and added the command as osascript /testscript running as root and I have set the command to run a few times on every day at just a few minutes from when I save the script. For example, I put “16,17,18,19” in the first field if it is now 15 minutes after the hour with * for all the other date entries, hoping the script will kick in after I close the crontab and run 4 times. I have explicitly set permissions on the file to 755 thinking there might be a permissions issue, but no go.

If anyone has info to share on getting Applescript to play with cron I would really appreciate it.

Running the script on a G5 with 10.4.3

cheers

if you saved the script as an application AND have the “Startup Screen” checked off - you’lle get a dialog box when it runs. Aslo - if you have a clean install of 10.43, and not an upgrade from 10.3 - Cron will not be availible - the new way to schedule jobs in 10.4 is with launchd.

Hmm… not regarding the service used, crond or launchd, I’m not sure whether it will be possible to run this command from within a daemon.
The reason is, that osascript needs a connection to the window manager in order to be able to execute a script (this is related to the AppleEvent manager, not to the osascript application itself) - and when invoking it from cron or a similar service, this connection is not present.

However, I’m currently working on a project that will allow exactly this (invoking AppleScripts without an initial connection to the window manager). Launching itself works, but I still have to do some cleaning and so on before I will deploy the tool. I will post it here, when I’m done.

Best regards,
danB