我想以编程方式修改 itunes 上轨道的文件系统路径,以便我可以将字符串转换应用于某些轨道位置(现在存储在文件系统上的不同位置)。
我已尝试使用 AppleScript 更新相关轨道的位置属性,但在调用“将 mytrack 的位置设置为 ...”时出现文件结束错误
我在网上看到过各种其他黑客攻击,涉及导出整个音轨数据库,以 XML 格式修改它,然后重新导入它——但这似乎丢失了太多元数据(例如播放列表)。
最佳答案
查看更多您的代码真的很有帮助。特别感兴趣的是您正在使用的值及其派生方式。查看您收到的确切错误消息也很有用(如果您从 Script Editor/ 运行程序,您应该能够从 AppleScript 错误对话框表中复制文本AppleScript 编辑器)。
file track
类的字典条目显示其 location
属性是一个可写的 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 路径名转换为 AppleScript 别名
,请使用以下表达式:
POSIX file str as alias
要将存储在变量 str
中的 HFS 路径名转换为 AppleScript 别名
,请使用以下表达式:
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
关于applescript - 以编程方式更新 iTunes 轨道位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2798866/