Running iSync from an Applescript is almost trivial, but I wanted my computer to do the following:
-- Before you use this script, launch /Applications/AppleScript/AppleScript Utility.app and check "Enable GUI Scripting."
-- The Bluetooth menu item must be turned on in the Bluetooth system preferences pane.
-- Check the current bluetooth status and turn it on if necessary.
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 "bluetooth menu extra" then exit repeat
end repeat
tell menu bar item x
click
tell 2nd menu item of front menu
if name ends with "Off" then
-- Current status is on; it says "turn bluetooth off"
set last_bluetooth_setting to "on"
else if name ends with "On" then
-- Current status is off; it says "turn bluetooth on"
set last_bluetooth_setting to "off"
click
end if
end tell
-- Unclick if it was on (do nothing but make the menu disappear)
if last_bluetooth_setting is "on" then
click
end if
end tell
end tell
-- Do the sync and wait for it to finish
tell application "iSync"
synchronize
repeat while (syncing is true)
delay 5
end repeat
set syncStatus to sync status
if syncStatus = 2 then
-- Success
quit
else
if syncStatus = 3 then
set syncStatus to "completed with warnings"
else if syncStatus = 4 then
set syncStatus to "completed with errors"
else if syncStatus = 5 then
set syncStatus to "last sync cancelled"
else if syncStatus = 6 then
set syncStatus to "last sync failed to complete"
else if syncStatus = 7 then
set syncStatus to "never synced"
end if
display dialog "syncStatus: " & syncStatus
syncStatus
end if
end tell
-- Set the bluetooth status to what it was before.
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 "bluetooth menu extra" then exit repeat
end repeat
tell menu bar item x
click
if last_bluetooth_setting is "off" then
-- Turn it off again
click 2nd menu item of front menu
else
-- Just close the menu
click
end if
end tell
end tell
Mac OS X Hints
http://hints.macworld.com/article.php?story=2006041922142626