我想编写一个AppleScript脚本,使我能够启动iTunes并指定一个特定的库,而不必按住Option键并浏览。我已经知道了Doug的Library Manager,但这并不是我想要的。该脚本是为一个特定的库设计的。
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
在内的行的注释。