Thursday, May 17, 2007

another month already

I can't believe another month has flown by already.
I was 'sposed to be in NZ next week for some P25 training, but I can't get anyone to look after Eli for the week. The next door neighbor has offered to look after him after school, or if I want a night out, but I think asking her to have him for 3 or 4 days is a bit much.

The car went in for its first service this week - 5000km already. I tried to give it a wash in the weekend and took it down to the local car wash, but now it looks worse than it did before. It's raining now, and I'm tempted to leave a couple of buckets outside to fill up with rain water and then wash it properly in the morning - hopefully it will still be raining so it'll get a rinse as well.

I've being playing around with apple script over the past we while and have managed to make a small program to fix my two gripes with OS X. Address book not auto connecting to my phone, and iSync not auto syncing.

There are few programs available that seem to now offer this type of functionality, Home Zone (http://metaquark.de/homezone/) is a nice one, but they tend to fill up the menu bar.
So I had a go at writing my own app that would just run as required. The result is "AutoSync" which was my first attempt. It basically just ran a script every 8 hours to run iSync. My reasoning that my Calendar and address book don't change that much, so if it updates once a day I'm set.
The next challange was to get address book to auto connect to my phone so that any SMSs were automatically displayed. I get about 20 SMSs a day, so it gets a bit annoying to have to pull my phone out every time I hear "You have a new SMS"

So now I have AutoSync 2.0 which now includes Address book re-connect.
The code is below...
-------------------------------------------
property interval : 480 * minutes
-- 480 minutes = 8 hours, 3 x a day
-- The intention is that it will sync at least once a day, and once overnight
-- Addressbook connect is to display any SMS's received overnight

on run
addressbook_Connect()
sync()
end run

on idle
addressbook_Connect()
sync()
return interval
end idle

-- Do the sync and wait for it to finish
to sync()
tell application "iSync"
if last sync is less than ((current date) - 600) then
-- Don't sync if less then 10 minutes since last sync (gets around the problem with doing two syncs when first run)
synchronize
end if
set miniaturized of first window to true
-- minimise the window while syncing
repeat while (syncing is true)
delay 25
-- wait 25 seconds for it to finish
end repeat
quit
end tell

end sync

-- Reconnect to the Address Book
to addressbook_Connect()
tell application "Address Book"
if not unsaved then
try
quit
delay 1
end try
end if
end tell
do shell script "defaults write com.apple.AddressBook ABCheckForPhoneNextTime -boolean true"
try
tell application "Address Book"
launch
end tell
tell application "System Events"
set the visible of process "Address Book" to no
end tell
end try
end addressbook_Connect

-----------------------------

to make this in to an application, save it as an application bundle and tick the "Stay open" option. The program will then run every 8 hours (or whatever you set the "interval" to).
I've given it a nice icon, and also managed to stop the application from being shown in the dock, but I can't remember how I did that now. I thought it was a line that I added to the plist file.

A copy of the application is available here

No comments: