代码之家  ›  专栏  ›  技术社区  ›  Kyle Hayes

使用特定库启动iTunes的AppleScript

  •  5
  • Kyle Hayes  · 技术社区  · 16 年前

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

    2 回复  |  直到 8 年前
        1
  •  12
  •   Nicholas Riley    8 年前

    iTunes不允许您使用AppleScript执行此操作,但您可以直接写入iTunes的首选项,其中它将书签(别名)存储到当前选定的库中(如果在默认位置使用库,则不存储任何内容)。

    首先,您需要获取所选库位置的别名数据。按住选项键打开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 .

        2
  •  3
  •   hotpaw2    15 年前

    您可以在unix shell脚本(man ln)中创建从~/music/itunes到所选目录路径的符号链接。applescript可以通过向终端应用程序发送适当的消息来调用unix shell脚本。