AppleScript to sync with iSync
Lately, I have been toying with automating some of my common tasks in OS X. I’m taking the same approach as I take to Emacs, which basically amounts to:
- Be aware of what you do.
- Identify patterns of repetitive actions which could be automated.
- Automate them.
I’ve been using iSync for a year or so now, but not very frequently. That changed last week, when I bought a new phone, and started making more use of it’s calender and to-do features. I found that I was synchronizing it more often than I had been before, and I found the process tedious. So I scripted it, instead.
I found a few examples of similar scripts, but none that did what I wanted. That was:
- Run invisibly, in the background.
- Quit iSync if the sync was successful.
- Alert me if the sync was not successful.
So, here is my script, which does just that. It’s under the BSD license.
-- Copyright ©2007, Ian Eure (http://atomized.org/2007/07/applescript-to-sync-with-isync/) -- All rights reserved. -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions are met: -- * Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- * Redistributions in binary form must reproduce the above copyright -- notice, this list of conditions and the following disclaimer in the -- documentation and/or other materials provided with the distribution. -- * Neither the name of thenor the -- names of its contributors may be used to endorse or promote products -- derived from this software without specific prior written permission. -- -- THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -- DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY -- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- Is iSync already running? tell application "System Events" to set isync_running to (name of processes) contains "iSync" tell application "iSync" activate if isync_running is not true then -- Hide the app if it wasn’t already open tell application "System Events" to set visible of process "iSync" to false end if synchronize -- Busy loop until sync is done repeat until syncing is false delay 1 end repeat -- Was the sync successful? if sync status is 2 then if isync_running is false then -- Yes, and iSync wasn’t already running - quit it -- Otherwise, we do nothing. quit end if else -- There was an error - focus iSync so the user can see it. activate end if end tell

October 13th, 2007 at 5:15 pm
Exactly what I was looking for. Thanks!