2009-11-07 55 views
5

我想编写一个AppleScript,允许我使用给定的库启动iTunes,而不必按住Option键并浏览一个。我已经知道道格的图书馆经理,这不是我想要的。 AppleScript将用于特定的库。Applescript用特定的库启动iTunes

回答

12

iTunes不允许您使用AppleScript来做到这一点,但您可以直接写入iTunes的偏好设置,在该偏好设置中存储当前所选库的别名(或者,如果您在默认情况下使用库位置)。

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

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

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

最后,这里的脚本:

property otherLibraryLocation : "" -- paste location between the quotes 
property libraryLocationPref : "com.apple.iTunes 'alis: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

+0

仍然适用于10.8.4! – Scot 2013-08-05 00:39:12

+0

不错!我想它会最终破裂,因为别名已被废弃,但在此期间... – 2013-08-06 00:28:00

+0

仍然在10.11.1工作! :d – Kametrixom 2015-11-28 23:26:36

3

您可以创建一个从〜/ Music/iTunes到unix shell脚本(man ln)中所选目录路径的符号链接。而AppleScript可以通过发送适当的消息到终端应用程序来调用一个unix shell脚本。