iPod Auto Sync Apple Script Help

Discussion in 'Mac Programming' started by vladimir929, Dec 21, 2008.

  1. vladimir929 macrumors newbie

    Joined:
    Oct 22, 2008
    #1
    I found an iPod sync applescript on the web and I tried adapting it to automatically sync the iPod every minute. I don't think it works, I was wondering if someone could help me. Thanks!

    property minutesBetweensync : 1
    tell application "iTunes"
    repeat with s in sources
    if (kind of s is iPod) then update s
    return minutesBetweensync * 60
    end repeat
    end tell
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    At a quick glance it seems like the return statement might be the problem as that will stop the loop.
     
  3. vladimir929 thread starter macrumors newbie

    Joined:
    Oct 22, 2008
    #3
    Thanks!

    Ok I removed the return but i still don't think its working. I'm sorry I have just started learning apple script. Thank you so much, you are a big help.

    property minutesBetweensync : 1
    tell application "iTunes"
    repeat with s in sources
    if (kind of s is iPod) then update s
    -- return minutesBetweensync * 60
    end repeat
    end tell
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    This should do what you want:
    Code:
    tell application "iTunes"
        set ipodsource to null
        repeat with s in sources
            if (kind of s is iPod) then
                set ipodsource to s
                exit repeat
            end if
        end repeat
    
        repeat
            update ipodsource
            delay 60
        end repeat
    end tell
    First it gets the iPod source, then it goes into an infinite loop. I use a delay to pause for 60 seconds, but the only problem is that when you use the update command, it's asynchronous so that AppleScript doesn't wait until the update command is finished before it continues with the next command. This results in the "delay 60" not being accurate.
     
  5. vladimir929 thread starter macrumors newbie

    Joined:
    Oct 22, 2008
    #5
    Thanks!

    That script works great. You helped me fix my problem and learn apple script at the same time :D!
     

Share This Page