I've been meaning to learn Applescript. It seems great for scripting all sorts of things. However, I've never got around to learning this
. Here's my first lame Applescript application.
I have a website (duh) that I would like to backup to my Powerbook weekly. Now the easiest thing to do would be to create a backup shell script and install this in cron. That's great for a machine on 24x7, but my laptop is not. Hmm, ok so let's use anacron. That will make sure my backup script runs. But then I thought, what if I suspend my powerbook during a backup. I wouldn't be able to know when the backup was running.
Ok, so how about bringing up a dialog before the backup starts (and ideally during the backup, but I couldn't figure this out). So began a sojourn into Applescript. I found this article describing cronning iTunes, and it's somewhat related to what I need to do. How do I display a dialog? Granted I would probably know this if I actually learned Applescript, but I found display dialog.
I brought up Script Editor and started playing with it. I'm impressed with how intuitive it is to write these scripts. It has a cool record function also, which I didn't use. I ended up with the script:
tell me activate end tell display dialog "Backup process will run in a few seconds" giving up after 3 do shell script "~/Backups/website/backup.sh >/dev/null"
The 'tell me' stuff was needed to bring the script to the foreground when it runs from cron. I found this by digging in this document. I had to save this as a 'Application' in Script Editor so I could run it from the command line.
I already had anacron installed, but the next issue was that it was only running root's scripts (periodic). I ended up adding a script to /etc/periodic/weekly/ with contents:
#!/bin/sh su - virajalankar -c /path/to/backup.app
This would run my Applescript as the proper user. It's sort of a clumsy solution though. I should probably put the backup logic in backup.app rather than a separate shell script. But like I said, I don't know alot of Applescript.
The end result is this script gets run 'weekly', and brings up a dialog just before it runs. It won't do much good if I don't have an Internet connection when it runs though
.
No Comments/Pingbacks for this post yet...
An ERROR has occured!
Here you might send email-notification to webmaster or something like that.