[AppleScript] How to tell when iPod sync is complete

Discussion in 'Mac Programming' started by wsha, Jan 5, 2012.

  1. wsha, Jan 5, 2012
    Last edited: Feb 12, 2012

    wsha macrumors newbie

    Aug 21, 2011
    Is there a way to tell when an iPod has finished sync'ing in iTunes?

    I have an AppleScript that I use when I want to pack up my MacBook Pro. It syncs my iPod with a tell to iTunes and then ejects all of my external hard drives including the iPod with a tell to Finder. I have the iPod set up as a disk drive so that Finder can eject it. I don't like using iTunes' eject in AppleScript because it shows an "are you sure?" dialog window.

    Apparently, AppleScript does not wait for the iPod to finish sync'ing after using the "update iPod" command before continuing the script because sometimes I get an error message saying that my iPod can not be ejected because iTunes is still using it. I put in a 10 second delay after the update command, but I don't like this solution because usually 10 seconds is too long so I am wasting a few seconds every time I do this and occasionally 10 seconds is not long enough and I get an error still.

    I have a feeling there is no simple way of checking if an iPod is currently being sync'ed or not (I have looked around a fair amount and not seen anything), but maybe there is a clever way of doing it? One promising command I found was the shell command lsof. However, it seems like my iPod does not show up in the output of lsof even when it is in use. Are there any other commands like this that could be tried? I also saw someone suggest tracking the free space on the iPod to see if it has stopped changing, but it seemed like that was not foolproof enough.

    Any ideas?


    Here is one way to tell when the iPod sync is complete:

    tell application "System Events" to tell application process "iTunes"
    set theStatusText to ""
    repeat until theStatusText is "iPod sync is complete."
    set theStatusText to value of static text 1 of scroll area 1 of window "iTunes"
    delay 1
    end repeat
    end tell

Share This Page