Performance Applescript-在库中迭代所有iTunes曲目时性能不佳
我正在尝试检查哪些曲目位于我的iTunes库目录中,哪些没有使用AppleScript 下面的脚本非常慢,每首曲目大约需要2秒(库中大约有8000首曲目): 还尝试了以下操作,但性能相同:Performance Applescript-在库中迭代所有iTunes曲目时性能不佳,performance,applescript,itunes,osx-elcapitan,Performance,Applescript,Itunes,Osx Elcapitan,我正在尝试检查哪些曲目位于我的iTunes库目录中,哪些没有使用AppleScript 下面的脚本非常慢,每首曲目大约需要2秒(库中大约有8000首曲目): 还尝试了以下操作,但性能相同: #!/usr/bin/osascript tell application "iTunes" repeat with l in (location of every file track) POSIX path of l does not start with
#!/usr/bin/osascript
tell application "iTunes"
repeat with l in (location of every file track)
POSIX path of l does not start with "/Users/user/Music/iTunes/iTunes Media/"
end repeat
end tell
与此同时,iTunes变得毫无反应
一定是在做傻事,但不知道是什么
这是在OS X El Capitan的2015 27'iMac上
谢谢你的帮助
干杯通过使用关键字
get
repeat with l in (get location of every file track)
区别在于:
- 如果不使用
,则会在每次迭代中检索列表get
- 使用
检索列表一次get
获取
事件(获取文件磁道1的位置
,获取文件磁道2的位置
,…)。首先获取所有位置的列表,然后对其进行迭代O(n*n)
而不是O(n)
效率)。你可以通过一个讨厌的黑客把它降到O(n)
,通过引用引用列表项(例如,将列表粘贴到脚本对象属性中,然后引用该属性)set iTunesFolder to POSIX path of (path to music folder) & "iTunes/iTunes Media/"
tell application "iTunes"
script
property fileLocations : location of every file track
end script
end tell
repeat with l in fileLocations of result
set fileName to (POSIX path of l)
if fileName does not start with iTunesFolder then log fileName
end repeat
完全正确谢谢
set iTunesFolder to POSIX path of (path to music folder) & "iTunes/iTunes Media/"
tell application "iTunes"
script
property fileLocations : location of every file track
end script
end tell
repeat with l in fileLocations of result
set fileName to (POSIX path of l)
if fileName does not start with iTunesFolder then log fileName
end repeat