09/04/28 11:50:58 OiCUS6iK0
ちゃんとパースする気なんかなかったけど。とりあえず手抜きで良いじゃんw
set theXML to "~/Desktop/'iTunes Music Library.xml'"
set tempFile to "~/Desktop/TempFile.txt"
do shell script "grep -E '<key>(Name|Artist|Album|Play (Count|Date UTC))</key>' " & theXML & " | perl -pe 'tr /\\t\\n//d; s,(<key>Name</key>),\\n$1,g; s,(\\d+);,chr $1,eg' >" & tempFile
tell application "iTunes"
set theTracks to selection of front browser window
repeat with aTrack in theTracks
tell aTrack
set theKey to "<key>Name</key><string>" & name & "</string><key>Artist</key><string>" & artist & "</string><key>Album</key><string>" & album & "</string>"
try
set theDelta to do shell script "grep " & quoted form of theKey & " " & tempFile & " | sed 1q | perl -pe 's,.*<key>Play Count</key><integer>(\\d+)</integer>.*,$1,'"
set oldCount to played count
set newCount to oldCount + theDelta
set played count to newCount
my ConsoleLog("new play count: " & newCount & " (was " & oldCount & ") for " & theKey)
on error
my ConsoleLog("can't find play count for: " & theKey)
end try
end tell
end repeat
end tell
on ConsoleLog(theLog)
do shell script "echo >/dev/console \"`date '+%b %e %H:%M:%S'`\" " & quoted form of theLog
end ConsoleLog