使用AppleScript启动具有特定库的iTunes

5
我想编写一个AppleScript脚本,使我能够启动iTunes并指定一个特定的库,而不必按住Option键并浏览。我已经知道了Doug的Library Manager,但这并不是我想要的。该脚本是为一个特定的库设计的。
2个回答

11

iTunes不允许你使用AppleScript来做这件事,但是你可以直接编写iTunes的偏好设置,其中存储着当前选择的库的书签(别名)(或者如果你正在使用默认位置的库,则不存储任何内容)。

首先,你需要获取所选库位置的别名数据。按住Option键打开iTunes,选择你的库并退出iTunes。然后,在终端中运行:

defaults read com.apple.itunes 'book:1:iTunes Library Location' | pbcopy

这将把库别名数据复制到剪贴板。

最后,这是脚本:

property otherLibraryLocation : "" -- paste location between the quotes
property libraryLocationPref : "com.apple.iTunes 'book:1:iTunes Library Location'"

-- first, quit iTunes if it's running
tell application "System Events"
    if exists (application process "iTunes") then
        tell application "iTunes" to quit
    end if
end tell

-- then, set the location
do shell script "defaults write " & libraryLocationPref & " " & quoted form of otherLibraryLocation
-- uncomment the following line to use the default iTunes library instead
-- do shell script "defaults delete " & libraryLocationPref

-- finally, relaunch iTunes
tell application "iTunes" to activate

复制库位置并粘贴到脚本的第一行引号之间,就可以完成全部设置。如果要返回原始库,请取消包括 defaults delete 在内的行的注释。


不错!我想它最终会崩溃,因为别名已被弃用,但在此期间... - Nicholas Riley
1
对于我来说(macOS 10.13.2,iTunes 12.7.4.76),这个默认值最近从“'alis:1:iTunes Library Location'”更改为“book:1:iTunes Library Location”,不确定何时更改,但如果上述解决方案不再适用于您,请尝试使用它。 - Jonas W
考虑到别名已被书签所取代,这是有道理的。 - Nicholas Riley
即使更改了属性键(book...),在iTunes 12.8上对我不再起作用。 - Augunrik
适用于iTunes 12.9 / macOS 10.14中的“书籍”位置。(我已经更新了我的答案,因为时间已经足够长!) - Nicholas Riley

3
您可以在Unix shell脚本中使用“ln”命令,从~/Music/iTunes创建符号链接到您选择的目录路径。同时,AppleScript可以通过向终端应用程序发送适当的消息来调用Unix shell脚本。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接