We’re using Macs as a kiosk here at the place that I work for customers that come into our branches. We noticed that people would leave personal documents they downloaded from the internet on the machines and we don’t have the manpower to constantly check these machines, so I started playing with Applescript.
The users are in Simple Finder mode with two Applescripts that run - the first just automatically opens the “My Applications” folder for easy use. The second is a little more complicated.
Basically, what I want the script to do is delete everything from the desktop as well as the documents folder every 5 minutes. Here is the script that I’m using:
tell application "Finder"
try
delete (every item of folder "Desktop" of folder "kioskuser" of folder "Users" of folder "Macintosh HD")
end try
try
delete (every item of folder "Documents" of folder "kioskuser" of folder "Users" of folder "Macintosh HD")
end try
empty trash
delay 300
end tell
Now, the script works perfectly fine. It deletes everything like it needs to and it empties the trash. The problem is this - every time the script runs, it basically causes the computer to seize. Someone mentioned trying to run the shell script “sleep”, but when I modified the app, it halted the computer immediately and gave me a “script error”, then proceeded to freeze the Finder.
Ideally, instead the leaving the app open and having it run on a delay, I’d like for it to open on a set interval, run, and then close itself. But I’m pretty sure that would have to be a script that run as a cron job, but I’m completely lost when it comes to cron scripting.
Does anyone have any suggestions on what I need to do to get this script to play nice?
I just went ahead and tried it under the Administrator account and under the kioskuser account. I created a rtf file using Textedit called cronjob with the contents of:
/5***‘/HD/DeleteDocs.app’
When I did a crontab, I get this error message:
/Users/user/Documents/cronjob.rtf:1: bad day-of-month
crontab: error in crontab file, can’t install
Even if I run crontab with a sudo and -u trigger, I get the same error.
I seem to have spoken too soon. The crontab took the file with no problem, but nothing actually happens. The app never runs.
If I run the app manually, it works perfectly fine. There is no mail for the system.
Another small edit - I went into the terminal and did a crontab -l and the cron job is indeed listed, so I know it’s there. Just don’t know why it’s not running.
I’m 99.9% certain my pathing is correct, because if I do the last section of the job (open ‘/path/to/.app’) from the Terminal, it runs just fine. Someone mentioned that I might need to make a cron.allow file?