我已将我的 iTunes 库与 Win7 台式机、MacBook 和 NAS 同步。
最初这似乎是个好主意,因为我的音乐/视频在所有设备上同步,当我带着 MacBook 外出时可以离线使用。然而,这带来了一个问题——冲突。
如果我同时打开多个 iTunes,就会发生冲突,因为它们不能很好地协同工作。所以我需要记住每次只打开一个 iTunes。除此之外,在切换台式机和笔记本电脑之间,我需要等到两台设备上的同步过程都完成。
我需要某种脚本来执行以下操作:
- 当用户尝试打开 iTunes 时,通过确认框提醒用户;或者
- 锁定打开 iTunes 的能力,直到所有同步完成为止;或者
- 强制执行令牌/密钥完整性,其中只有一个设备在任何一个给定点拥有密钥。使用此密钥,用户可以打开 iTunes。这可能只是文本文件中的布尔值。或者也许文本文件的存在就足够了。
我的问题是 - 我可以用什么来做上述任何一件事?我不知道从哪里开始,也不知道有哪些应用程序可以帮助我做到这一点。
答案1
经过一番研究,我找到了一种在 Windows 7 中自动执行此操作的方法:自动热键
我编写了一个脚本,用于在打开 iTunes 时创建一个文本文件以与 NAS 同步。此文本文件是打开它的计算机独有的密钥,并且仅在相关计算机处于“在线”状态时才会创建/删除,以确保完整性。
#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
我希望这对其他人有所帮助。我现在正在寻找 Mac OSX 解决方案。我将做一些研究自动机看看是否可行。如果其他人有其他解决方案,请分享。