我想从 ruby 更新 iTunes 中的曲目路径,但无法正常工作。出于某种原因,我对 track.setLocation() 的调用什么也没做。这是我正在使用的脚本:
require 'osx/cocoa'
include OSX
OSX.require_framework 'ScriptingBridge'
def getSourceLibrary(iTunes)
iTunes.sources.each do |source|
if (source.kind == 1800169826) # TV Kind
return source
end
end
return nil
end
iTunes = SBApplication.applicationWithBundleIdentifier:'com.apple.iTunes'
library=getSourceLibrary(iTunes)
libraryPlaylists=library.libraryPlaylists
libraryPlaylists[0].fileTracks.each do | track |
if (track.videoKind==1800823892)
loc = track.location.to_s
puts "Before: #{loc}"
loc = loc.gsub(/\/mounts\/TVShows/,'/mounts/TV')
loc = loc.gsub(/\/mounts\/incoming/,'/mounts/TV')
track.setLocation(loc)
puts "After: #{track.location.to_s}"
end
end
该脚本遍历 iTunes 库并尝试更改路径。不过前后是一样的!即使正则表达式搜索和替换有效。对此的任何帮助将不胜感激。