One of the problems I’ve discovered with using iSync is that there doesn’t seem to be a way to schedule it. A few people have solutions but all of them open the full iSync application; I prefer using the menubar icon which opens iSync but doesn’t pop up any extra windows on top of what I’m doing.

I started with a basic sync script, then followed one of the comments to an advanced script that toggles the bluetooth state via the menu bar before syncing. I don’t need to turn off BT, but the script gave me a good starting point for what I wanted to do. After some quick debugging to find the iSync menu name, I now have my script – it still has to switch the focus to the menu bar for a second but it happens so fast that I doubt I’ll notice.

Here’s the script for anyone who is interested – although it has only been tested on 10.5. It looks horrible in the width-restricted blog theme but it will copy/paste correctly (or just load it via the RSS feed):

tell application “System Events” to tell the front menu bar of process “SystemUIServer”
    set menu_extras to value of attribute “AXDescription” of menu bar items
    repeat with x from 1 to the length of menu_extras
        if item x of menu_extras is “Sync” then exit repeat
    end repeat
    tell menu bar item x
        click
        tell 3rd menu item of front menu
            click
        end tell
    end tell
end tell

For those of you who are scared of shell scripting there’s even CronniX to help you schedule it (hat tip to the original article for that link). It’s still a confusing process if you’re not familiar with crontab but it’s easier than learning the file format.

Just don’t forget that you have to use the osascript command to run applescript files, and you have to manually enable GUI scripting via the AppleScript application before this script will work.

Advertisements