我想以编程方式修改iTunes上音轨的文件系统路径,以便可以对某些音轨位置(现在存储在文件系统上的其他位置)进行字符串转换。
[我尝试使用AppleScript更新相关轨道的location属性,但是在调用“将mytrack的位置设置为...时,出现文件结尾错误”
[我在网上看到了其他各种骇客,涉及到导出整个track db,以XML对其进行修改,然后重新导入-但这似乎丢失了太多的元数据(例如播放列表)。
脚本编辑器 / AppleScript编辑器运行程序,则应该能够从AppleScript错误对话框页面中复制文本。 )。
file track
类的字典条目显示其location
属性为可写的alias
值。您可能遇到的问题是您没有使用别名作为值。以下代码显示了如何使用choose file
中的交互式提示(返回alias
)来更改轨道的位置:
set m to path to music folder
tell application "iTunes"
set trk to first item of selection
set l to location of trk
if class of l is alias then
set m to l
end if
set {d, a, n} to {database ID, artist, name} of trk
choose file with prompt "Choose the file to use for " & d & ": " & a & "—" & n default location m
set location of trk to result
end tell
choose file
方法不是您想要的,因为您正在执行某种自动的,基于字符串的路径名转换。在AppleScript中使用路径名时,可以使用两种:POSIX和HFS。 POSIX路径名具有以斜杠分隔的组件(并允许在任何组件内部使用冒号)。 HFS路径名具有用冒号分隔的组件(并且在任何组件中都允许使用斜杠),并且它们通常以卷名组件开头。
要将存储在变量
str
中的POSIX路径名转换为AppleScriptalias
,请使用以下表达式:
POSIX file str as alias
要将存储在变量str
中的HFS路径名转换为AppleScriptalias
,请使用以下表达式:
alias str
例如:
tell application "iTunes" set trk to first item of selection set l to location of trk set newPath to my computeNewPath(POSIX path of l) set location of trk to POSIX file newPath as alias end tell to computeNewPath(pp) -- presumably something interesting happens here return pp end computeNewPath
iTunes Library.itl
)完好无损的同时,将媒体文件(不是由iTunes进行“整理”的文件移动到另一个位置:mv ~/MyMusic /Volumes/Huge/
)ln -s /Volumes/Huge/MyMusic ~/MyMusic
)-- Mark missing tracks (and update database with real path of existing
-- tracks) in iTunes
-- Instructions:
-- * symlink new file location to old location (old location points to
-- new location, file exists)
-- * select tracks to scan/update
-- * run the script
-- * missing tracks are marked with (!) and all other track paths have
-- been updated to the real path (symlinks eliminated) in iTunes
tell application "iTunes"
set fx to fixed indexing
set fixed indexing to true
set Sel to the selection
repeat with i from 1 to number of items in Sel
set trk to item i of Sel
set loc to (get location of trk as text)
end repeat
set fixed indexing to fx
end tell
如果没有获得符号链接,则iTunes会在每个丢失的曲目旁边显示(!)
。要解决此问题,只需在旧位置创建一个指向新位置的符号链接,然后再次运行脚本。提示:“获取信息”对话框可用于确定丢失曲目的旧位置。
这在iTunes 11.0.5上有效
tell application "Music"
set fx to fixed indexing
set fixed indexing to true
set Sel to the selection
repeat with i from 1 to number of items in Sel
set trk to item i of Sel
set l to location of trk
set location of trk to l
end repeat
set fixed indexing to fx
end tell