I got really tired of the fact that my phone was always out of sync with my address book and calendar on my laptop. This is the longest period in my life I've consistently kept a calendar and address book up-to-date and accurate. (The first time, I've really needed to.) Anyway, I decided to fix the problem and came up with a handy little AppleScript to handle the issue. Then, I run it from cron once an hour.
A few concerns:
- The sync must happen in the background. I don't want to be bothered when it happens. I haven't quite succeeded here, but it's good enough for me.
- I want to be notified when it fails. I don't want to find out that iSync hasn't succeeded in two weeks when I suddenly really need it and my phone is near and my laptop is not.
- I don't want iSync open when it doesn't need to be. I have a nasty habit of forgetting to close applications as it is. I don't need yet another icon sitting on the Dock.
- I don't want to get errors when my phone isn't near my laptop. If I'm away from my laptop with my phone or I've forgotten my phone, I don't want to get a message every hour telling me this. Duh, I know that.
I handle (1) by hiding the iSync window as soon as it opens. This means that it pops up briefly, but Apple is smart enough to not steal focus in this case. I probably could have hacked my way through and figured out how the iSync icon on the menubar activates syncserve, which is how it does it without opening the iSync application. However, I'll save that for the next revision.
I handle (2) and (3) by looping until the sync is complete. I don't know why busy waiting doesn't cause the script to take up more CPU, but I assume that the script engine must have some way of detecting busy waiting or simply nicing it down. Whatever it does, it doesn't cause a problem. I was going to add a sleep in the midst of the loop, but I couldn't find the solution after a few seconds. Again, perhaps a feature for the next revision but it doesn't seem to be a problem. Anyway, once iSync reports it is done, I check the result status. If the result status is happy, I quit. If there are errors, I leave the application open, which will show a popup on the screen (supplied by iSync automatically) containing the error log. Good enough.
The last part (4) was the most fun. I have a copy of Salling Clicker, which automatically connects to my phone via Bluetooth when it can. I check it before each run to see if the phone is connected. If it isn't, we quit without iSync. If it is, we run iSync. Easy. I imagine this script could probably be modified to do something similar by attempting to establish a Bluetooth connection via Address. I could also improve mine by checking to see if I've told it to stop trying to connect and either warning my that iSync won't run or by trying to reactivate the connection.
Finally, to run the script I added the following to my crontab:
5 * * * * /usr/bin/osascript $HOME/bin/iSync-Now.scpt
Okay, enough explanation. If you want the script to check out for yourself. See the attachment link below.
Cheers.

Leave a comment