Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Automatically sync when connecting an iPod iPod
In older versions of iTunes you had the option to perform a sync, similar to clicking the Sync button in iSync in Mac OS X 10.5 and newer. For me this was a perfect solution to remember syncing my phones since I connected my iPod once a day to update some smart playlists. To mimic this functionlity I wrote an AppleScript and then attached it as a folder action to the /Volumes folder.

Here's the script:
global bluetoothActive
property blueutilPath : "$HOME/bin/blueutil"

on adding folder items to this_folder after receiving added_items
  set podName to "the name of your iPod"
  if podName is in (added_items as string) then
    if "on" is in (do shell script blueutilPath & " status") then
      set bluetoothActive to true
    else
      set bluetoothActive to false
      do shell script blueutilPath & " on"
    end if
    try
      tell application "Finder"
        if exists POSIX file "/tmp/sync" then
          set newAddresses to (do shell script "find $HOME'/Library/Application Support/AddressBook/Metadata' -newer /tmp/sync")
          set newEvent to (do shell script "find $HOME/Library/Calendars -newer /tmp/sync")
          if "ics" is in newEvent then
            display dialog "new event " & newEvent giving up after 5
            my sync()
          else if "abcd" is in newAddresses then
            display dialog "new contact: " & newAddresses giving up after 5
            my sync()
          end if
        else
          my sync()
        end if
      end tell
    on error errStr number errorNumber
      display dialog "find failed " & errStr & errorNumber giving up after 5
      my sync()
      
    end try
    if not bluetoothActive then
      do shell script blueutilPath & " off"
    end if
  end if
end adding folder items to

on sync()
  tell application "iSync"
    try
      synchronize
    on error
      display dialog "Sync failed"
    end try
    repeat while (syncing)
    end repeat
    if (sync status is 2 or 3) then
      do shell script "touch /tmp/sync"
    else
      do shell script "rm /tmp/sync"
    end if
  end tell
end sync
Some remarks:
  • If you sync using Bluetooth, you need blueutil. Put it into ~/bin.
  • On the fourth line of code, enter the name of the iPod (or the name of whatever you want to trigger a sync when it is added to /Volumes)
  • It checks if there are some new or changed events or contacts since last sync (by comparing the timestamps of the iCal and Address Book databases with the time of the last sync). However, this does not work very well, it almost always seems to be new/changed events/contacts, even when I have touched the applications. If someone knows a better way (by asking iCal/Address Book?) to verify this, please comment. It would also be useful if you could limit this check to calenders/contact groups you actually sync.
Now I just wonder if any of the Hints readers could tell me how do this over the network (my current setup is to sync my iPod on one machine and have my Address Book/iCal on another machine). I am aware of ssh machine osascript -e path/to/script but for academic purposes I want to use remote Apple Events.

[crarko adds: I haven't tested this one. The script compiles without error and I've mirrored it here.]
    •    
  • Currently 1.67 / 5
  You rated: 2 / 5 (9 votes cast)
 
[6,124 views]  

Automatically sync when connecting an iPod | 7 comments | Create New Account
Click here to return to the 'Automatically sync when connecting an iPod' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Automatically sync when connecting an iPod
Authored by: Unsoluble on Oct 19, '10 08:13:55AM

I'm trying really hard, but I can't figure out what problem this hint solves.



[ Reply to This | # ]
Automatically sync when connecting an iPod
Authored by: fracai on Oct 19, '10 09:41:17AM

I think it's supposed to tell iSync to perform a synchronization task with the user's other phones whenever the iPod is connected.

But, I really can't be sure.

---
i am jack's amusing sig file



[ Reply to This | # ]
Automatically sync when connecting an iPod
Authored by: rv8 on Oct 19, '10 08:48:50AM

How is this hint better than going into iTunes Preferences, Devices section, and deselecting the "Prevent iPods, iPhones and iPads from syncing automatically" option?

---
Kevin Horton



[ Reply to This | # ]
Maybe...
Authored by: morespace54 on Oct 19, '10 10:04:41AM

Maybe the OP wants to auto-syn his iPod but not his phone...
In this case, the trick above (stop iTunes to auto-sync devices from the iTunes pref pane) wouldn't work. So maybe is trying to auto-sync is iPod and "manually-auto-sync" his phone only (while "auto-auto-sync" his iPod)... Just a guess...

Edited on Oct 19, '10 10:06:33AM by morespace54



[ Reply to This | # ]
Automatically sync when connecting an iPod
Authored by: david-bo on Oct 19, '10 10:20:46AM

You know, there are other phones than iPhones. I use iSync to sync two phones (private and work) via bluetooth. As I wrote in the hint, in older version of iTunes you had en option to run iSync when you connected an iPod. Since I connect my iPod every day that meant that both my phones automatically where synced (=backed up) every day. Unfortunately Apple removed this feature but this script restores a functionality at least Apple (and I) considered useful.

---
link



[ Reply to This | # ]
Automatically sync when connecting an iPod
Authored by: Unsoluble on Oct 19, '10 03:09:57PM

Oooohhhh, okay. That makes a lot of sense now. The fact that you were talking about iSync and third-party phones -- as opposed to iTunes and iPhones -- was not at all clear in the actual hint.



[ Reply to This | # ]
SyncBar to the rescue
Authored by: dirkwald on Oct 20, '10 12:31:59AM

Have you tried SyncBar yet? SyncBar

It launches iSync at regular intervals, eg. mine is set to sync every two hours... I absolutely love it.



[ Reply to This | # ]