Automating iSync and Bluetooth
With some pointers from friends I've beaten applescript into submission and coded up a script to automate the bluetooth iSync syncing with my phone.
The script opens up System Preferences and enables Bluetooth, then launches iSync and instructs it to sync. It will then leave Bluetooth in the state that it found it in.
The code is below for anyone who might find it handy :) Oh and for the record this is written to run on Mac OS X Leopard.
display dialog "Sync?" buttons {"Ok", "Cancel"} default button 2
if the button returned of the result is "Cancel" then
stop
end if
tell application "System Preferences"
activate
set current pane to pane "com.apple.preferences.Bluetooth"
tell application "System Events" to tell window "Bluetooth" of process "System Preferences"
set was_on to the value of checkbox "On"
if value of checkbox "On" is equal to 0 then
tell checkbox "On" to click
end if
end tell
end tell
tell application "iSync"
synchronize
repeat while (syncing is true)
delay 5
end repeat
set syncStatus to sync status
if syncStatus is not 2 then
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
end if
quit
end tell
if was_on is equal to 0 then
tell application "System Preferences"
set current pane to pane "com.apple.preferences.Bluetooth"
tell application "System Events" to tell window "Bluetooth" of process "System Preferences"
if value of checkbox "On" is 1 then
tell checkbox "On" to click
end if
end tell
quit
end tell
end if
