0

I've synced my iTunes library with a Win7 Desktop, a MacBook, and a NAS.

Initially it seems like a good idea because my music/videos were synced across all devices and are available offline when I'm on the go with my MacBook. However, this presented a problem - conflict.

If I have more than one iTunes open at any given time, there is a conflict, because they don't play nicely together. So I need to remember to only have one iTunes open at any one given time. On top of this, I need to wait until the syncing process is complete on both devices, in between switching my Desktop and Laptop.

I need some sort of script that will either:

  1. Remind user with a confirmation box when they attempt to Open iTunes; or
  2. Lock the ability to open iTunes until all sync is complete; or
  3. Enforce token/key integrity, where only one device will have a key at any one given point. With this key, the user can open iTunes. This could simply be a boolean in a text file. Or perhaps the presence of the text file is sufficient.

My question is - What can I use to do any of the above? I don't know where to begin and what applications are available that can help me do this.

1
  • Can you use Home Sharing? The "master" Mac in my house is set up with Home Sharing, and the "client" Macs and ATVs pick up all the iTunes content from the master. This works for viewing, but doesn't allow you to edit the iTunes library - you still have to go to the master Mac (or PC) for that. – jimtut Oct 15 '14 at 12:24
0

After some research I found a way to automate this in Windows 7: AutoHotKey

I've written a script to create a text file to sync with the NAS while iTunes is opened. This text file is a key unique to the computer opening it and will only be created/removed when the computer in question is "online" to ensure integrity.

#NoTrayIcon
; the only way to keep integrity is to make sure that everything is synced before creating or deleting key
; if there is no key, only create one when there is internet connection, which is a safe bet that it is synced.

NodeNam = www.google.com
IPs := HostToIp(NodeName)
DllCall("Ws2_32\WSACleanup") ; always inlude this line after calling to release the socket connection

IfNotExist, %A_WorkingDir%\*Key.txt
{
    if IPs <> -1
        FileAppend, This file represents iTunes key`n, %A_WorkingDir%\Win7Key.txt ;Msgbox, %NodeName%`n%IPs%
}


;if the right key exist, allow iTunes to run, and delete key only if internet is available
IfExist, %A_WorkingDir%\Win7Key.txt
{
  Run, "C:\Program Files (x86)\iTunes\iTunes.exe"
  winWait, iTunes
  winWaitClose
  if IPs <> -1
    FileDelete, %A_WorkingDir%\Win7Key.txt
}

;checks if internet is available by querying www.google.com
HostToIp(NodeName) ; returns -1 if unsuccessful or a newline seperated list of valid IP addresses
{
    VarSetCapacity(wsaData, 32)  ; The struct is only about 14 in size, so 32 is conservative.
    result := DllCall("Ws2_32\WSAStartup", "UShort", 0x0002, "UInt", &wsaData) ; Request Winsock 2.0 (0x0002)
    if ErrorLevel   ; check ErrorLevel to see if the OS has Winsock 2.0 available:
    {
        MsgBox WSAStartup() could not be called due to error %ErrorLevel%. Winsock 2.0 or higher is required.
        return -1
    }
    if result  ; Non-zero, which means it failed (most Winsock functions return 0 on success).
    {
        MsgBox % "WSAStartup() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError") ; %
        return -1
    }
    PtrHostent := DllCall("Ws2_32\gethostbyname", str, Nodename)
    if (PtrHostent = 0) 
        Return -1 
    VarSetCapacity(hostent,16,0) 
    DllCall("RtlMoveMemory",UInt,&hostent,UInt,PtrHostent,UInt,16)  
    h_addr_list := ExtractInteger(hostent,12,false,4)  
    VarSetCapacity(AddressList,12,0) 
    DllCall("RtlMoveMemory",UInt,&AddressList,UInt,h_addr_list,UInt,12) 
    Loop, 3 
    { 
       offset := ((A_Index-1)*4) 
       PtrAddress%A_Index% := ExtractInteger(AddressList,offset,false,4) 
       If (PtrAddress%A_Index% =0) 
          break 
       VarSetCapacity(address%A_Index%,4,0) 
       DllCall("RtlMoveMemory" ,UInt,&address%A_Index%,UInt,PtrAddress%A_Index%,Uint,4) 
       i := A_Index 
       Loop, 4 
       { 
          if Straddress%i% 
             Straddress%i% := Straddress%i% "." ExtractInteger(address%i%,(A_Index-1 ),false,1) 
          else 
             Straddress%i% := ExtractInteger(address%i%,(A_Index-1 ),false,1) 
       }
        Straddress0 = %i%
    }
    loop, %Straddress0% ; put them together and return them
    {
        _this := Straddress%A_Index%
        if _this <>
            IPs = %IPs%%_this%
        if A_Index = %Straddress0%
            break
        IPs = %IPs%`n
    }
    return IPs
} 
ExtractInteger(ByRef pSource, pOffset = 0, pIsSigned = false, pSize = 4)
{ 
    Loop %pSize% 
      result += *(&pSource+pOffset+A_Index-1) << 8*A_Index-8 
    Return result 
}

ExitApp

I hope this help someone else. I'm now looking for a Mac OSX solution. I will be doing some research on Automator to see if possible. If someone else has any other solution please share.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.