Thursday, February 12, 2009

Dipping wary toes in the water of Applescript

Actually, this has turned out to be slightly less scary than I thought. Here's the project.

I like my paper diary, but it doesn't have alarms, so if I'm not careful about looking in my diary at regular intervals during the day, I'm likely to forget or a miss an appointment. I've long since given up on trying to carry all the data around in my head, so a diary is essential. 

The problems of alarms is solved by making sure my Mac diary is up-to-date with my paper diary and then synchronised to my 'phone. I have a Nokia 6085 that I've made compatible with iSync. So far so good. The only thing is that I have to remember to perform the sync regularly.

So I got to thinking. It's a Bluetooth 'phone and there must be a way of automating the process. My daughter Ally has shown me how to use Automator to do things like this, but I also thought it should be possible to use the Bluetooth connectivity to trigger the event. A quick search found a little utility called Proximity.

Proximity detects Bluetooth devices when they come into range of your computer and will run scripts when it does so. It can also run scripts when they go out of range too, so you could use your Bluetooth 'phone to lock your Mac when you leave the office my running an appropriate script.

Next I needed some help with the script. Knowing nothing about Applescript I searched for some help. I found exactly what I wanted here. And used the following bit of script to fire up iSync:


tell application "iSync"
if last sync is less than ((current date) - 900) then
synchronize
end if
end tell

Essentially this performs a sync every 15 minutes, which I think I'll change to an hour, and I need to modify it to do two things if possible. First I want it to quit iSync when it's finished. I'm sure that's just the addition of a simple line of code,. I just need to find the code!

 Secondly, I'd like, if possible, to figure out how to sync my Palm PDA  automatically (I use that as a diary and address book backup device) without having to press the button or just to ignore the PDA and do that manually as and when.

So there's work to be done, but it seems to be functioning okay at the moment. I'll be going out soon, so we'll see what happens when I come back in range!

2 comments:

Anonymous said...

I have an iPhone but the diary annoys me because not every event has a definate end time and some events don't have start times they are just there!

I like the idea of the auto-sync!

Richard said...

There other ways I've discovered. One neat solution is to create a synchronise calendar (which you can hide of course) and set a daily or hourly event that runs the script. Might even be better than proximity, although I guess yo could script that into it.

I suspect I'll be trawling through the mind of a mutually known MacAddict's mind when I next speak to him.